Skip to content

Commit

Permalink
Merge pull request #1155 from decko-commons/ethn-wikirate
Browse files Browse the repository at this point in the history
handle blank codenames in migrations
  • Loading branch information
ethn authored Feb 7, 2025
2 parents 837dfdb + 36a6ed4 commit 5e4c184
Show file tree
Hide file tree
Showing 182 changed files with 8,387 additions and 10,947 deletions.
23 changes: 12 additions & 11 deletions card/lib/card/env/location_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ def save_location card
return unless save_location?(card)

discard_locations_for card
session[:previous_location] =
Env::Location.card_path card.name.url_key
location_history.push previous_location
end

def save_location? card
!Env.ajax? && Env.html? && card.known? && (card.codename != :signin)
location_history.push location_for_history(card)
end

def previous_location
return unless location_history

session[:previous_location] ||= location_history.last
location_history&.last
end

def discard_locations_for card
Expand All @@ -35,7 +27,6 @@ def discard_locations_for card
url_key.to_name.key == card.key
end
end.compact
session[:previous_location] = nil
end

def save_interrupted_action uri
Expand All @@ -46,9 +37,19 @@ def interrupted_action
session.delete :interrupted_action
end

private

def location_for_history card
Env::Location.card_path card.name.url_key
end

def url_key_for_location location
%r{/([^/]*$)} =~ location ? Regexp.last_match[1] : nil
end

def save_location? card
!Env.ajax? && Env.html? && card.known? && (card.codename != :signin)
end
end
end
end
4 changes: 2 additions & 2 deletions card/lib/card/set/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Helpers
# Card::Set::Type::User
def shortname
first = 2 # shortname eliminates Card::Set
last = first + num_set_parts(pattern_code)
last = pattern_code == :self ? -1 : (first + num_set_parts)
set_name_parts[first..last].join "::"
end

Expand Down Expand Up @@ -115,7 +115,7 @@ def nonbase_format_modules format_sym
Card::Set.modules[set_format_type_key][format_class][shortname] || []
end

def num_set_parts pattern_code
def num_set_parts
return 1 if pattern_code == :abstract

Pattern.find(pattern_code).anchor_parts_count
Expand Down
7 changes: 5 additions & 2 deletions card/lib/card/set/pattern/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Pattern
# class from which set patterns inherit
class Base
extend ClassMethods
delegate :pattern_code, :pattern, :anchorless?, :anchor_parts_count,
:assigns_type, to: :class
delegate :pattern_code, :pattern, :anchorless?, :assigns_type, to: :class

def initialize card
return if anchorless?
Expand Down Expand Up @@ -43,6 +42,10 @@ def anchor_codenames
end
end

def anchor_parts_count
@anchor_parts_count ||= self.class.anchor_parts_count @anchor_name
end

def anchor_parts
return [@anchor_name] unless anchor_parts_count > 1

Expand Down
2 changes: 1 addition & 1 deletion card/lib/card/set/pattern/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def pattern_applies? card
compound_only? ? card.name.compound? : true
end

def anchor_parts_count
def anchor_parts_count _anchor_name=nil
@anchor_parts_count ||= (anchorless? ? 0 : 1)
end

Expand Down
10 changes: 10 additions & 0 deletions card/lib/cardio/mod/loader/set_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ def location_method
def postamble
"end;" * (@modules.size + 3)
end

# [set_registration, ends].compact.join "\n"
# end
#
# def set_registration
# "Card::Set.register_set self" unless helper_module?
# end
#
# def ends
# end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions card/mod/core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ en:
core_error_cant_alter: can't alter this type; %{name} cards still exist
core_error_cant_change_errors: "of %{name} can't be changed; errors creating new %{type_id}: %{error_messages}"
core_error_code_in_use: codename %{codename} already in use
core_codename_must_be_simple: only simple cards can have codenames
core_error_hard_templated: can't be changed because %{name} is hard templated to %{type_name}
core_error_indestructible: "%{name} is an indestructible rule"
core_error_invalid_character_in_cardtype: "may not contain any of the following characters: %{banned}"
Expand Down
8 changes: 8 additions & 0 deletions card/mod/core/data/schema/20241017160402_unique_codename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class UniqueCodename < Cardio::Migration::Schema
def up
remove_blank_codenames
remove_index :cards, name: "cards_codename_index"
add_index :cards, :codename, name: "cards_codename_index", unique: true
end
Expand All @@ -10,4 +11,11 @@ def down
remove_index :cards, name: "cards_codename_index"
add_index :cards, :codename, name: "cards_codename_index"
end

private

def remove_blank_codenames
Cardio::Record.connection
.execute "UPDATE cards SET codename = null where codename = ''"
end
end
7 changes: 7 additions & 0 deletions card/mod/core/set/all/codename.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
event :validate_codename, :validate, on: :update, changed: :codename do
validate_codename_permission
validate_codename_uniqueness
validate_codename_simplicity
end

event :reset_codename_cache, :integrate, changed: :codename do
Expand Down Expand Up @@ -30,3 +31,9 @@ def validate_codename_uniqueness

errors.add :codename, t(:core_error_code_in_use, codename: codename)
end

def validate_codename_simplicity
return if name.simple?

errors.add :codename, t(:core_codename_must_be_simple)
end
4 changes: 4 additions & 0 deletions card/mod/core/set_pattern/09_self.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ def anchor_name card
def anchor_id card
card.id
end

def anchor_parts_count anchor_name=nil
anchor_name&.part_names&.size || 1
end
22 changes: 13 additions & 9 deletions card/spec/cardio/mod/loader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding : utf-8 -*-

describe Cardio::Mod::Loader do
RSpec.describe Cardio::Mod::Loader do
# let(:card_double) { double "Card" }
# let(:pat_all_double) { proxy Card::Set::All }
# let(:format_double) { proxy Card::Format }
Expand Down Expand Up @@ -51,16 +51,18 @@ def hello
end

it "loads self set for junction card" do
create_card "set+test+load", codename: "set_test_load"
create_card ":set+:css"
Card::Cache.reset_all
module Card::Set::Self::SetTestLoad
extend Card::Set
def hello
"hello"
module Card::Set::Self::Set
module Css
extend Card::Set
def hello
"hello"
end
end
end

expect(Card["set+test+load"]).to respond_to :hello
expect(Card["set+css"]).to respond_to :hello
end

it "loads type set" do
Expand All @@ -75,8 +77,10 @@ def hello
expect(Card.new(name: "test load", type: "set test load")).to respond_to :hello
end

it "loads type set for a junction cardtyp" do
create_card "set+test load", codename: "set_test_load", type_id: Card::CardtypeID
it "loads type set for a compound cardtype" do
# now that compound cards can't have codenames, for this to work, we will need to
# make it so that type sets can have multi-codename modules
create_card "set+test load", codename: "set_test_load", type: :cardtype
Card::Cache.reset_all
module Card::Set::Type::SetTestLoad
extend Card::Set
Expand Down
2 changes: 1 addition & 1 deletion docker/repos/decko-k8s.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ WORKDIR /home/app/decko

COPY --chown=app:app . .

RUN cp -R vendor/decko/docker/template/config/* config
RUN cp -Rn vendor/decko/docker/template/config/* config
# && \
# cp -R config/sample/* config

Expand Down
9 changes: 1 addition & 8 deletions mod/assets/set/abstract/asset_outputter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,11 @@ def make_asset_output_coded mod
mod ||= :assets
Card::Auth.as_bot do
ENV["STORE_CODED_FILES"] = "true"
asset_output_card.update! storage_type: :coded, mod: mod,
codename: asset_output_codename
asset_output_card.update! storage_type: :coded, mod: mod
ENV["STORE_CODED_FILES"] = nil
end
end

def asset_output_codename
asset_output_card.name.parts.map do |part|
Card[part].codename&.to_s || part.cardname.safe_key
end.join "_"
end

def input_item_cards
item_cards(known_only: true).compact.reject(&:trash)
end
Expand Down
2 changes: 1 addition & 1 deletion mod/assets/spec/set/abstract/asset_outputter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
it "creates coded file" do
mod_path = Cardio::Mod.dirs.path "format"
path = File.join mod_path,
"data", "files", "mod_format_script_asset_output", "file.js"
"data", "files", "mod_format", "script", "asset_output", "file.js"
expect(File).to be_exist(path),
"Decko should be shipped with generated script file. " \
"Couldn't find #{path}"
Expand Down
2 changes: 1 addition & 1 deletion mod/bar_and_box/spec/set/abstract/media_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def text_with_image args={}
end

it "takes image card object as image" do
expect(text_with_image(image: Card[:yeti_skin_image]))
expect(text_with_image(image: %i[yeti_skin image].card))
.to have_tag :div, with: { class: "media" } do
with_tag "img[src*='/files/']", with: { alt: "yeti skin+Image" }
end
Expand Down
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit 5e4c184

Please sign in to comment.