card 1.108.1 → 1.109.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/environments/development.rb +1 -1
  4. data/config/environments/production.rb +5 -2
  5. data/config/initializers/01_core_extensions/array.rb +1 -0
  6. data/config/initializers/01_core_extensions/hash.rb +4 -0
  7. data/config/initializers/02_patches/active_record.rb +1 -1
  8. data/config/initializers/core_extensions.rb +0 -1
  9. data/config/initializers/deck_config.rb +3 -3
  10. data/config/initializers/patches.rb +6 -6
  11. data/lib/card/auth/current.rb +8 -6
  12. data/lib/card/auth.rb +7 -6
  13. data/lib/card/cache/class_methods.rb +2 -4
  14. data/lib/card/cache/shared.rb +1 -1
  15. data/lib/card/cache/temporary.rb +2 -2
  16. data/lib/card/codename.rb +0 -1
  17. data/lib/card/content/chunk/abstract.rb +1 -0
  18. data/lib/card/content/chunk.rb +0 -1
  19. data/lib/card/content/clean.rb +4 -2
  20. data/lib/card/content/diff/l_c_s.rb +1 -2
  21. data/lib/card/content/diff/result.rb +2 -1
  22. data/lib/card/content/diff.rb +2 -1
  23. data/lib/card/content/parser.rb +8 -7
  24. data/lib/card/content.rb +1 -1
  25. data/lib/card/director/subdirector_array.rb +1 -0
  26. data/lib/card/director.rb +1 -1
  27. data/lib/card/dirty/method_factory.rb +1 -0
  28. data/lib/card/env/location.rb +3 -3
  29. data/lib/card/env/location_history.rb +12 -11
  30. data/lib/card/env/success/target.rb +4 -4
  31. data/lib/card/env/support.rb +24 -2
  32. data/lib/card/error.rb +1 -0
  33. data/lib/card/fetch/store.rb +1 -1
  34. data/lib/card/format/error.rb +1 -0
  35. data/lib/card/format/method_delegation.rb +6 -4
  36. data/lib/card/format/registration.rb +5 -3
  37. data/lib/card/format/wrapper.rb +1 -0
  38. data/lib/card/mailer.rb +1 -14
  39. data/lib/card/name/all/parts.rb +1 -1
  40. data/lib/card/name/all.rb +1 -0
  41. data/lib/card/name/name_variants.rb +1 -0
  42. data/lib/card/query/abstract_query/query_helper.rb +1 -2
  43. data/lib/card/query/abstract_query/tie.rb +1 -1
  44. data/lib/card/query/abstract_query.rb +3 -3
  45. data/lib/card/query/card_class.rb +1 -0
  46. data/lib/card/query/clause.rb +1 -0
  47. data/lib/card/query/join.rb +3 -3
  48. data/lib/card/reference/all.rb +6 -7
  49. data/lib/card/rule/cache.rb +1 -0
  50. data/lib/card/rule/preference_cache.rb +2 -0
  51. data/lib/card/rule/read_rule_cache.rb +3 -0
  52. data/lib/card/set/event/all.rb +6 -4
  53. data/lib/card/set/event/callbacks.rb +1 -0
  54. data/lib/card/set/event/options.rb +3 -2
  55. data/lib/card/set/event/skip_and_trigger.rb +1 -1
  56. data/lib/card/set/event.rb +2 -2
  57. data/lib/card/set/format/abstract_format/view_definition.rb +1 -1
  58. data/lib/card/set/format/haml_paths.rb +1 -1
  59. data/lib/card/set/format.rb +4 -4
  60. data/lib/card/set/helpers.rb +4 -4
  61. data/lib/card/set/i18n_scanner.rb +23 -22
  62. data/lib/card/set/i18n_scope.rb +4 -3
  63. data/lib/card/set/pattern/all.rb +1 -1
  64. data/lib/card/set/pattern/base.rb +6 -3
  65. data/lib/card/set/pattern/class_methods.rb +1 -1
  66. data/lib/card/set/pattern.rb +1 -1
  67. data/lib/card/set/required_field.rb +3 -0
  68. data/lib/card/set/trait.rb +6 -1
  69. data/lib/card/subcards/all.rb +12 -4
  70. data/lib/card/view/cache/cache_action.rb +1 -1
  71. data/lib/card/view/cache.rb +1 -1
  72. data/lib/card/view/classy.rb +5 -5
  73. data/lib/card/view/options/key_lists.rb +1 -0
  74. data/lib/card/view/options/voo_api.rb +1 -1
  75. data/lib/cardio/command/application.rb +1 -1
  76. data/lib/cardio/command/custom.rb +7 -6
  77. data/lib/cardio/command/rake_command.rb +3 -2
  78. data/lib/cardio/command/rspec_command.rb +1 -0
  79. data/lib/cardio/generators/deck_generator_loader.rb +1 -1
  80. data/lib/cardio/generators.rb +4 -3
  81. data/lib/cardio/migration/port.rb +2 -0
  82. data/lib/cardio/migration/stamp.rb +1 -0
  83. data/lib/cardio/migration/transform.rb +1 -0
  84. data/lib/cardio/migration.rb +2 -0
  85. data/lib/cardio/mod/class_methods.rb +1 -2
  86. data/lib/cardio/mod/dirs.rb +2 -4
  87. data/lib/cardio/mod/eat/edibles.rb +8 -6
  88. data/lib/cardio/mod/eat.rb +6 -5
  89. data/lib/cardio/mod/load_strategy/set_binding_magic.rb +1 -1
  90. data/lib/cardio/mod/load_strategy/tmp_files.rb +3 -2
  91. data/lib/cardio/mod/load_strategy.rb +1 -0
  92. data/lib/cardio/mod/loader/set_pattern_loader.rb +4 -0
  93. data/lib/cardio/mod/loader/set_template.rb +14 -4
  94. data/lib/cardio/mod/loader.rb +2 -2
  95. data/lib/cardio/mod/sow/card_source.rb +1 -1
  96. data/lib/cardio/mod/sow/remote_source.rb +32 -0
  97. data/lib/cardio/mod/sow.rb +10 -10
  98. data/lib/cardio/railtie.rb +1 -0
  99. data/lib/cardio/script_loader.rb +1 -1
  100. data/lib/cardio/seed.rb +1 -1
  101. data/lib/cardio/utils.rb +1 -1
  102. data/lib/cardio/version.rb +2 -1
  103. data/lib/cardio.rb +3 -0
  104. data/lib/generators/deck/templates/config.ru.erb +1 -1
  105. data/mod/core/config/locales/en.yml +1 -0
  106. data/mod/core/data/schema/20141001105348_move_revisions_to_actions.rb +2 -2
  107. data/mod/core/data/schema/20241017160402_unique_codename.rb +8 -0
  108. data/mod/core/data/transform/20150724123438_update_file_and_image_cards.rb +1 -1
  109. data/mod/core/lib/tasks/card/export.rake +28 -0
  110. data/mod/core/lib/tasks/card/migrate.rake +3 -3
  111. data/mod/core/lib/tasks/card/seed.rake +2 -1
  112. data/mod/core/lib/tasks/card.rake +47 -16
  113. data/mod/core/set/all/admin.rb +1 -2
  114. data/mod/core/set/all/assign_attributes.rb +3 -2
  115. data/mod/core/set/all/codename.rb +7 -0
  116. data/mod/core/set/all/debug.rb +3 -3
  117. data/mod/core/set/all/initialize.rb +1 -0
  118. data/mod/core/set/all/states.rb +7 -6
  119. data/mod/core/set/all/type.rb +2 -0
  120. data/mod/core/set/all/utils.rb +0 -1
  121. data/mod/core/set/self/admin.rb +2 -1
  122. data/mod/core/set/self/autoname.rb +1 -1
  123. data/mod/core/set/self/mod.rb +4 -4
  124. data/mod/core/set/self/trash.rb +1 -1
  125. data/mod/core/set/type/mod.rb +18 -15
  126. data/mod/core/set_pattern/09_self.rb +4 -0
  127. data/mod/core/spec/set/all/trash_spec.rb +7 -7
  128. metadata +42 -29
@@ -6,6 +6,7 @@ module Cardio
6
6
  # enhance standard rake command with some decko/card -specific options
7
7
  class RakeCommand < CommandBase
8
8
  def initialize gem, command, args=[]
9
+ super()
9
10
  @command = command
10
11
  @task = "#{gem}:#{command}"
11
12
  @args = [args].flatten
@@ -33,8 +34,8 @@ module Cardio
33
34
  def commands
34
35
  task_cmd = "bundle exec rake #{@task}"
35
36
  task_cmd += " -- #{escape_args(@args).join ' '}" unless @args.empty?
36
- puts task_cmd
37
- return [task_cmd] if !@envs || @envs.empty?
37
+ puts task_cmd.yellow
38
+ [task_cmd] if !@envs || @envs.empty?
38
39
 
39
40
  # @envs.map do |env|
40
41
  # "env RAILS_ENV=#{env} #{task_cmd}"
@@ -8,6 +8,7 @@ module Cardio
8
8
  def initialize args
9
9
  require "rspec/core"
10
10
 
11
+ super()
11
12
  cardio_args, @rspec_args = split_args args
12
13
  @opts = {}
13
14
  Parser.new(@opts).parse!(cardio_args)
@@ -1,2 +1,2 @@
1
1
  require "cardio/generators"
2
- require File.expand_path("../../../generators/deck/deck_generator", __FILE__)
2
+ require File.expand_path("../../generators/deck/deck_generator", __dir__)
@@ -11,9 +11,9 @@ module Cardio
11
11
  module ClassMethods
12
12
  def source_root path=nil
13
13
  if path
14
- @_card_source_root = path
14
+ @source_root = path
15
15
  else
16
- @_card_source_root ||= File.expand_path(
16
+ @source_root ||= File.expand_path(
17
17
  "../../generators/#{generator_name}/templates", __FILE__
18
18
  )
19
19
  end
@@ -33,7 +33,8 @@ module Cardio
33
33
  # Override Rails namespace handling so we can put generators in `module Cardio`
34
34
  def namespace name=nil
35
35
  return super if name
36
- @namespace ||= super.sub(/cardio:/, "")
36
+
37
+ @namespace ||= super.sub("cardio:", "")
37
38
  end
38
39
  end
39
40
  delegate :banner_command, to: :class
@@ -10,6 +10,7 @@ module Cardio
10
10
 
11
11
  def port
12
12
  return unless lease_connection.table_exists? old_deck_table
13
+
13
14
  rename_old_tables
14
15
  lease_connection.execute "INSERT INTO #{table} (#{select_nonduplicate_versions})"
15
16
  lease_connection.drop_table old_deck_table
@@ -25,6 +26,7 @@ module Cardio
25
26
  def rename_old_tables
26
27
  old_tables.each do |old_table_name|
27
28
  next unless lease_connection.table_exists? old_table_name
29
+
28
30
  lease_connection.rename_table old_table_name, table
29
31
  end
30
32
  end
@@ -5,6 +5,7 @@ module Cardio
5
5
  def stamp
6
6
  mode do
7
7
  return unless (version = stampable_version) && (file = stamp_file)
8
+
8
9
  puts ">> writing version: #{version} to #{file.path}"
9
10
  file.puts version
10
11
  end
@@ -32,6 +32,7 @@ module Cardio
32
32
 
33
33
  def contentedly
34
34
  return yield if ENV["NO_CARD_LOAD"]
35
+
35
36
  Card::Cache.reset_all
36
37
  Card::Auth.as_bot do
37
38
  yield
@@ -1,6 +1,8 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Cardio
4
+ # Base class for both schema and transform card migrations,
5
+ # which are found in <mod>/data/schema and <mod>/data/transform respectively
4
6
  class Migration < ActiveRecord::Migration[6.1]
5
7
  include Assumption
6
8
  include Stamp
@@ -42,7 +42,6 @@ module Cardio
42
42
  def ensure_installed
43
43
  Card::Auth.as_bot do
44
44
  Card::Cache.reset_all
45
- puts "installing card mods".green
46
45
  ensure_asset_lists do |hash|
47
46
  puts "ensuring mod and asset cards"
48
47
  Cardio.mods.each { |mod| ensure_asset_cards mod.ensure_card, hash }
@@ -108,7 +107,7 @@ module Cardio
108
107
 
109
108
  # @return [True/False]
110
109
  def gem_spec? spec
111
- return unless spec
110
+ return false unless spec
112
111
 
113
112
  spec.name.match?(/^card-mod-/) || spec.metadata["card-mod"].present?
114
113
  end
@@ -129,10 +129,8 @@ module Cardio
129
129
  end
130
130
  end
131
131
 
132
- def each_subpath *subdirs
133
- subpaths(*subdirs).each do |mod_name, subpath|
134
- yield mod_name, subpath
135
- end
132
+ def each_subpath *subdirs, &block
133
+ subpaths(*subdirs).each(&block)
136
134
  end
137
135
 
138
136
  private
@@ -15,7 +15,7 @@ module Cardio
15
15
  return yield unless @name
16
16
 
17
17
  yield.select do |edible|
18
- if @name.match?(/^\:/)
18
+ if @name.match?(/^:/)
19
19
  explicit_codename_match? edible[:codename]
20
20
  else
21
21
  explicit_name_match? edible[:name]
@@ -24,7 +24,7 @@ module Cardio
24
24
  end
25
25
 
26
26
  def explicit_codename_match? codename
27
- codename && (codename == @name[1..-1])
27
+ codename && (codename == @name[1..])
28
28
  end
29
29
 
30
30
  def explicit_name_match? name
@@ -98,7 +98,7 @@ module Cardio
98
98
 
99
99
  def mod_file mod, filename
100
100
  unless (mod_file_path = mod.subpath "data/files", filename)
101
- raise StandardError, "#{filename} not found. "\
101
+ raise StandardError, "#{filename} not found. " \
102
102
  "Should be in data/files in #{mod.name} mod."
103
103
  end
104
104
  File.open mod_file_path
@@ -109,16 +109,18 @@ module Cardio
109
109
  end
110
110
 
111
111
  def pod_types
112
- if @pod_type == :all
112
+ if all_pod_types?
113
113
  %i[real test]
114
114
  elsif @pod_type
115
115
  [@pod_type]
116
- elsif Rails.env.test?
117
- %i[real test]
118
116
  else
119
117
  [:real]
120
118
  end
121
119
  end
120
+
121
+ def all_pod_types?
122
+ @pod_type == :all || (Rails.env.test? && !@pod_type)
123
+ end
122
124
  end
123
125
  end
124
126
  end
@@ -19,13 +19,13 @@ module Cardio
19
19
  @verbose = !verbose.nil?
20
20
  end
21
21
 
22
- def up
22
+ def run
23
23
  handle_up do
24
24
  edibles.each do |edible|
25
25
  track edible do
26
26
  current_user edible.delete(:user)
27
27
  time_machine edible.delete(:time) do
28
- Card.ensure edible
28
+ Card.ensure! edible
29
29
  end
30
30
  end
31
31
  end
@@ -35,10 +35,10 @@ module Cardio
35
35
  private
36
36
 
37
37
  # if output mod given,
38
- def handle_up
38
+ def handle_up &block
39
39
  Card::Cache.reset_all
40
40
  Card::Mailer.perform_deliveries = false
41
- Card::Auth.as_bot { yield }
41
+ Card::Auth.as_bot(&block)
42
42
  :success
43
43
  rescue StandardError => e
44
44
  e.message
@@ -76,7 +76,8 @@ module Cardio
76
76
  case value
77
77
  when /^[+-]\d+$/
78
78
  # plus or minus an integer (safe to eval)
79
- eval "#{Time.now.to_i} #{value}", binding, __FILE__, __LINE__
79
+ eval "#{Time.now.to_i} #{value}", # 1741296981 +1 (e.g.)
80
+ binding, __FILE__, __LINE__ - 1
80
81
  when Integer
81
82
  value
82
83
  else
@@ -39,7 +39,7 @@ module Cardio
39
39
  mod.name.split("::").each do |part|
40
40
  m, b =
41
41
  eval(
42
- "[ #{part} , #{part}.module_eval('binding') ]",
42
+ "[ #{part} , #{part}.module_eval('binding') ]", # [ History , History.module_eval('binding') ]
43
43
  b
44
44
  )
45
45
  end
@@ -24,9 +24,10 @@ module Cardio
24
24
  end
25
25
 
26
26
  def rewrite_tmp_files?
27
- return @rewrite if defined? @rewrite
27
+ return @rewrite_tmp_files if defined? @rewrite_tmp_files
28
28
 
29
- @rewrite = !(Rails.env.production? && Card.paths["tmp/set"].existent.first)
29
+ @rewrite_tmp_files =
30
+ !(Rails.env.production? && Card.paths["tmp/set"].existent.first)
30
31
  end
31
32
 
32
33
  def write_tmp_file from_file, to_file, const_parts
@@ -33,6 +33,7 @@ module Cardio
33
33
  end
34
34
 
35
35
  attr_reader :loader
36
+
36
37
  delegate :template_class, :pattern_groups, :each_file, :mod_dirs, :parts_from_path,
37
38
  to: :loader
38
39
 
@@ -1,6 +1,9 @@
1
1
  module Cardio
2
2
  class Mod
3
3
  class Loader
4
+ # arguably overkill, the set pattern loader makes set patterns use
5
+ # directory/file-aware loading much as set patterns do. Since they are so
6
+ # rarely added, this optimization should probably be deprecated
4
7
  class SetPatternLoader < Loader
5
8
  def template_class
6
9
  SetPatternTemplate
@@ -17,6 +20,7 @@ module Cardio
17
20
  end
18
21
  end
19
22
 
23
+ # templates for set pattern modules
20
24
  class SetPatternTemplate < ModuleTemplate
21
25
  def to_const
22
26
  return Object if simple_load?
@@ -28,9 +28,9 @@ module Cardio
28
28
  format_name = Regexp.last_match(1)
29
29
  format_name = format_name.blank? ? nil : format_name.to_sym
30
30
  "module #{module_name format_name}; " \
31
- "module_parent.send :register_set_format, "\
32
- "#{format_class format_name}, self; "\
33
- "extend Card::Set::AbstractFormat"
31
+ "module_parent.send :register_set_format, " \
32
+ "#{format_class format_name}, self; " \
33
+ "extend Card::Set::AbstractFormat"
34
34
  end
35
35
  end
36
36
 
@@ -92,7 +92,7 @@ module Cardio
92
92
  def pattern_label *anchors
93
93
  anchor_count = pattern_class.anchor_parts_count
94
94
  label = pattern_class.label(pattern_anchor(*anchors, anchor_count))
95
- remainder = anchors[anchor_count..-1]
95
+ remainder = anchors[anchor_count..]
96
96
  label += " (#{remainder.join ', '})" if remainder.any?
97
97
  label
98
98
  end
@@ -125,6 +125,16 @@ module Cardio
125
125
  def postamble
126
126
  "end;" * (@modules.size + 3)
127
127
  end
128
+
129
+ # [set_registration, ends].compact.join "\n"
130
+ # end
131
+ #
132
+ # def set_registration
133
+ # "Card::Set.register_set self" unless helper_module?
134
+ # end
135
+ #
136
+ # def ends
137
+ # end
128
138
  end
129
139
  end
130
140
  end
@@ -28,7 +28,7 @@ module Cardio
28
28
  end
29
29
 
30
30
  def load_initializers
31
- Cardio.config.paths["late/initializers"].existent.sort.each do |init|
31
+ Cardio.config.paths["late/initializers"].existent.each do |init|
32
32
  load init
33
33
  end
34
34
  end
@@ -60,7 +60,7 @@ module Cardio
60
60
 
61
61
  def parts_from_path path
62
62
  # remove file extension and number prefixes
63
- parts = path.gsub(/\.rb/, "").gsub(%r{(?<=\A|/)\d+_}, "").split(File::SEPARATOR)
63
+ parts = path.gsub(/\.rb$/, "").gsub(%r{(?<=\A|/)\d+_}, "").split(File::SEPARATOR)
64
64
  parts.map(&:camelize)
65
65
  end
66
66
 
@@ -1,7 +1,7 @@
1
1
  module Cardio
2
2
  class Mod
3
3
  class Sow
4
- # Fetch sow data form cards
4
+ # Fetch sow data from cards
5
5
  module CardSource
6
6
  def new_data_from_cards
7
7
  cards.map { |c| c.pod_hash field_tags: field_tag_marks }
@@ -0,0 +1,32 @@
1
+ module Cardio
2
+ class Mod
3
+ class Sow
4
+ # Fetch sow data from remote
5
+ module RemoteSource
6
+ def remote_source
7
+ @remote_source ||=
8
+ if @remote
9
+ raise Card::Error::NotFound, "must specify name (-n)" unless @name
10
+
11
+ URI.join(@remote, "/#{@name.cardname.url_key}/", "pod.yml")
12
+ else
13
+ @url
14
+ end
15
+ end
16
+
17
+ def pod_from_url
18
+ parsed_yaml = parse_pod_yaml yaml_from_url
19
+ Array.wrap(parsed_yaml)
20
+ rescue Psych::SyntaxError
21
+ raise "Url #{@remote_source} provided invalid yaml"
22
+ end
23
+
24
+ def yaml_from_url
25
+ @yaml_from_url ||= URI.open(@remote_source).read
26
+ rescue OpenURI::HTTPError => e
27
+ raise "#{@remote_source} not available\n#{e}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -7,25 +7,25 @@ module Cardio
7
7
  class Sow
8
8
  include YamlDump
9
9
  include CardSource
10
+ include RemoteSource
10
11
 
11
12
  def initialize **args
12
13
  @mod = args[:mod]
13
14
  @name = args[:name]
14
15
  @cql = args[:cql]
15
16
  @url = args[:url]
17
+ @remote = args[:remote]
16
18
  @podtype = args[:podtype] || (Rails.env.test? ? :test : :real)
17
19
  @items = args[:items]
18
20
  @field_tags = args[:field_tags]
19
21
  end
20
22
 
21
23
  # if output mod given,
22
- def out
24
+ def run
23
25
  Card::Cache.reset_all
24
26
  @mod ? dump(output_hash) : puts(new_data.to_yaml.yellow)
25
27
  :success
26
- rescue Card::Error::NotFound => e
27
- e.message
28
- rescue JSON::ParserError => e
28
+ rescue Card::Error::NotFound, JSON::ParserError => e
29
29
  e.message
30
30
  end
31
31
 
@@ -42,8 +42,11 @@ module Cardio
42
42
 
43
43
  # @return [Array <Hash>]
44
44
  def new_data
45
- @new_data ||=
46
- @url ? pod_hash_from_url : new_data_from_cards
45
+ @new_data ||= fetch_new_data
46
+ end
47
+
48
+ def fetch_new_data
49
+ remote_source ? pod_from_url : new_data_from_cards
47
50
  end
48
51
 
49
52
  def merge_data
@@ -72,11 +75,8 @@ module Cardio
72
75
 
73
76
  def old_data
74
77
  return unless File.exist? filename
75
- parse_pod_yaml File.read(filename)
76
- end
77
78
 
78
- def pod_hash_from_url
79
- parse_pod_yaml URI.open(@url).read
79
+ parse_pod_yaml File.read(filename)
80
80
  end
81
81
 
82
82
  def parse_pod_yaml pod_yaml
@@ -38,6 +38,7 @@ module Cardio
38
38
  config.raise_all_rendering_errors = false
39
39
 
40
40
  config.cache_set_module_list = false
41
+ config.max_temporary_cache_keys = 10_000
41
42
 
42
43
  config.i18n.enforce_available_locales = true
43
44
  config.read_only = !ENV["DECKO_READ_ONLY"].nil?
@@ -46,7 +46,7 @@ module Cardio
46
46
 
47
47
  def in_application_subdirectory? path=Pathname.new(Dir.pwd)
48
48
  File.exist?(File.join(path, script)) ||
49
- !path.root? && in_application_subdirectory?(path.parent)
49
+ (!path.root? && in_application_subdirectory?(path.parent))
50
50
  end
51
51
  end
52
52
 
data/lib/cardio/seed.rb CHANGED
@@ -64,7 +64,7 @@ module Cardio
64
64
 
65
65
  def write_seed_file table
66
66
  filename = File.join default_path, "#{table}.yml"
67
- File.open(filename, "w") { |file| file.write yield }
67
+ File.write(filename, yield)
68
68
  end
69
69
 
70
70
  def yamlize_records table
data/lib/cardio/utils.rb CHANGED
@@ -58,7 +58,7 @@ module Cardio
58
58
 
59
59
  def all_file_ids
60
60
  dir = Card.paths["files"].existent.first
61
- Dir.entries(dir)[2..-1].map(&:to_i)
61
+ Dir.entries(dir)[2..].map(&:to_i)
62
62
  end
63
63
 
64
64
  def all_trashed_card_ids
@@ -1,12 +1,13 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  module Cardio
4
+ # handle version numbers for releases
4
5
  module Version
5
6
  class << self
6
7
  CARD_MINOR = { 0 => 90, 1 => 1000 }.freeze # can remove and hardcode after 1.0
7
8
 
8
9
  def release
9
- @version ||= File.read(File.expand_path("../../VERSION", __dir__)).strip
10
+ @release ||= File.read(File.expand_path("../../VERSION", __dir__)).strip
10
11
  end
11
12
 
12
13
  def card_release
data/lib/cardio.rb CHANGED
@@ -8,6 +8,9 @@ ActiveSupport.on_load :after_card do
8
8
  Cardio::Mod.load
9
9
  end
10
10
 
11
+ # Cardio is a quick loading module and is at the heart (get it?) of
12
+ # card loading and configuration because it is useful long before the Card class is
13
+ # (or card objects are)
11
14
  module Cardio
12
15
  extend Delaying
13
16
 
@@ -8,4 +8,4 @@ if Rails.env.profile?
8
8
  end
9
9
 
10
10
  <% end -%>
11
- run <%= app_const %>
11
+ run Cardio.application.class
@@ -8,6 +8,7 @@ en:
8
8
  core_error_cant_alter: can't alter this type; %{name} cards still exist
9
9
  core_error_cant_change_errors: "of %{name} can't be changed; errors creating new %{type_id}: %{error_messages}"
10
10
  core_error_code_in_use: codename %{codename} already in use
11
+ core_codename_must_be_simple: only simple cards can have codenames
11
12
  core_error_hard_templated: can't be changed because %{name} is hard templated to %{type_name}
12
13
  core_error_indestructible: "%{name} is an indestructible rule"
13
14
  core_error_invalid_character_in_cardtype: "may not contain any of the following characters: %{banned}"
@@ -3,7 +3,7 @@ class MoveRevisionsToActions < Cardio::Migration::Schema
3
3
  belongs_to :tmp_card, foreign_key: :card_id
4
4
  self.table_name = "card_revisions"
5
5
  def self.delete_cardless
6
- left_join = "LEFT JOIN cards "\
6
+ left_join = "LEFT JOIN cards " \
7
7
  "ON card_revisions.card_id = cards.id"
8
8
  TmpRevision.joins(left_join).where("cards.id IS NULL").delete_all
9
9
  end
@@ -55,7 +55,7 @@ class MoveRevisionsToActions < Cardio::Migration::Schema
55
55
 
56
56
  def create_create_action rev
57
57
  TmpAction.connection.execute(
58
- "INSERT INTO card_actions (id, card_id, card_act_id, action_type) VALUES "\
58
+ "INSERT INTO card_actions (id, card_id, card_act_id, action_type) VALUES " \
59
59
  "('#{rev.id}', '#{rev.card_id}', '#{rev.id}', 0)")
60
60
  if (tmp_card = rev.tmp_card)
61
61
  TmpChange.connection.execute "INSERT INTO card_changes (card_action_id, field, value) VALUES
@@ -2,6 +2,7 @@
2
2
 
3
3
  class UniqueCodename < Cardio::Migration::Schema
4
4
  def up
5
+ remove_blank_codenames
5
6
  remove_index :cards, name: "cards_codename_index"
6
7
  add_index :cards, :codename, name: "cards_codename_index", unique: true
7
8
  end
@@ -10,4 +11,11 @@ class UniqueCodename < Cardio::Migration::Schema
10
11
  remove_index :cards, name: "cards_codename_index"
11
12
  add_index :cards, :codename, name: "cards_codename_index"
12
13
  end
14
+
15
+ private
16
+
17
+ def remove_blank_codenames
18
+ Cardio::Record.connection
19
+ .execute "UPDATE cards SET codename = null where codename = ''"
20
+ end
13
21
  end
@@ -88,7 +88,7 @@ class UpdateFileAndImageCards < Cardio::Migration::Transform
88
88
  def get_new_file_name filename
89
89
  original_filename = filename
90
90
  if filename =~ /^(icon|small|medium|large|original)-([^.]+).(.+)$/
91
- filename = "#{Regexp.last_match(2)}-#{Regexp.last_match(1)}."\
91
+ filename = "#{Regexp.last_match(2)}-#{Regexp.last_match(1)}." \
92
92
  "#{Regexp.last_match(3)}"
93
93
  end
94
94
  filename = filename.downcase
@@ -0,0 +1,28 @@
1
+ require "csv"
2
+
3
+ namespace :card do
4
+ namespace :export do
5
+ desc "export all cards to csv"
6
+ task csv: :environment do
7
+ parse_options :csv do
8
+ add_opt :f, :file, "file name"
9
+ end
10
+ filename = options[:file] || "cards.csv"
11
+ puts "Exporting all card data to #{filename}..."
12
+ File.write(filename) { |f| f.write to_csv }
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def to_csv
20
+ attributes = %w[id name codename type content]
21
+
22
+ CSV.generate(headers: true) do |csv|
23
+ csv << attributes
24
+ Card.all.each do |card|
25
+ csv << attributes.map { |attr| card.send(attr) }
26
+ end
27
+ end
28
+ end
@@ -1,4 +1,3 @@
1
-
2
1
  namespace :card do
3
2
  desc "migrate structure and cards"
4
3
  task migrate: :environment do
@@ -47,6 +46,7 @@ namespace :card do
47
46
 
48
47
  task port: :environment do
49
48
  puts "porting"
49
+ ENV["NO_CARD_LOAD"] = "true"
50
50
  Cardio::Migration.port_all
51
51
  end
52
52
 
@@ -60,7 +60,7 @@ namespace :card do
60
60
  end
61
61
 
62
62
  def version
63
- ENV["VERSION"] ? ENV["VERSION"].to_i : nil
63
+ ENV["VERSION"]&.to_i
64
64
  end
65
65
  end
66
66
  end
@@ -109,7 +109,7 @@ end
109
109
  # FIXME: too general
110
110
  # intent is to find Record classes; this gets a lot more.
111
111
  def load_mod_lib
112
- Dir.glob(Cardio.root.join("mod/*/lib/*.rb")).sort.each { |x| require x }
112
+ Dir.glob(Cardio.root.join("mod/*/lib/*.rb")).each { |x| require x }
113
113
  end
114
114
 
115
115
  def without_dumping
@@ -34,6 +34,7 @@ namespace :card do
34
34
 
35
35
  # desc "dump db to fixtures"
36
36
  task dump: :environment do
37
+ puts "dumping".green
37
38
  Card::Cache.reset_all
38
39
  Cardio::Seed.dump
39
40
  end
@@ -54,7 +55,7 @@ namespace :card do
54
55
  end
55
56
 
56
57
  def invoke_card_task task
57
- puts "invoking: #{task}".green
58
+ puts "invoking: #{task}"
58
59
  Rake::Task["card:#{task}"].invoke
59
60
  end
60
61
  end