card 1.108.1 → 1.109.1

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 (148) 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/config/locales/es.yml +2 -3
  12. data/db/seeds.rb +0 -1
  13. data/lib/card/auth/current.rb +8 -6
  14. data/lib/card/auth/permissions.rb +1 -1
  15. data/lib/card/auth/proxy.rb +2 -2
  16. data/lib/card/auth/setup.rb +2 -2
  17. data/lib/card/auth.rb +7 -6
  18. data/lib/card/cache/all.rb +1 -1
  19. data/lib/card/cache/class_methods.rb +2 -4
  20. data/lib/card/cache/shared.rb +1 -1
  21. data/lib/card/cache/temporary.rb +2 -2
  22. data/lib/card/codename.rb +1 -1
  23. data/lib/card/content/chunk/abstract.rb +1 -0
  24. data/lib/card/content/chunk.rb +0 -1
  25. data/lib/card/content/clean.rb +4 -2
  26. data/lib/card/content/diff/l_c_s.rb +1 -2
  27. data/lib/card/content/diff/result.rb +2 -1
  28. data/lib/card/content/diff.rb +2 -1
  29. data/lib/card/content/parser.rb +8 -7
  30. data/lib/card/content.rb +1 -1
  31. data/lib/card/director/subdirector_array.rb +1 -0
  32. data/lib/card/director.rb +1 -1
  33. data/lib/card/dirty/method_factory.rb +1 -0
  34. data/lib/card/env/location.rb +3 -3
  35. data/lib/card/env/location_history.rb +20 -20
  36. data/lib/card/env/success/target.rb +4 -4
  37. data/lib/card/env/support.rb +25 -2
  38. data/lib/card/error.rb +1 -0
  39. data/lib/card/fetch/store.rb +1 -1
  40. data/lib/card/format/error.rb +13 -2
  41. data/lib/card/format/method_delegation.rb +6 -4
  42. data/lib/card/format/registration.rb +5 -3
  43. data/lib/card/format/render.rb +51 -47
  44. data/lib/card/format/wrapper.rb +1 -0
  45. data/lib/card/lexicon.rb +5 -2
  46. data/lib/card/mailer.rb +1 -14
  47. data/lib/card/name/all/parts.rb +1 -1
  48. data/lib/card/name/all.rb +5 -0
  49. data/lib/card/name/name_variants.rb +1 -0
  50. data/lib/card/query/abstract_query/query_helper.rb +1 -2
  51. data/lib/card/query/abstract_query/tie.rb +1 -1
  52. data/lib/card/query/abstract_query.rb +3 -3
  53. data/lib/card/query/card_class.rb +1 -0
  54. data/lib/card/query/card_query/relational_attributes.rb +1 -1
  55. data/lib/card/query/card_query/run.rb +5 -1
  56. data/lib/card/query/clause.rb +1 -0
  57. data/lib/card/query/join.rb +3 -3
  58. data/lib/card/query/sql_statement.rb +7 -1
  59. data/lib/card/query.rb +1 -1
  60. data/lib/card/reference/all.rb +6 -7
  61. data/lib/card/rule/cache.rb +1 -0
  62. data/lib/card/rule/preference_cache.rb +2 -0
  63. data/lib/card/rule/read_rule_cache.rb +3 -0
  64. data/lib/card/set/event/all.rb +6 -4
  65. data/lib/card/set/event/callbacks.rb +1 -0
  66. data/lib/card/set/event/options.rb +3 -2
  67. data/lib/card/set/event/skip_and_trigger.rb +1 -1
  68. data/lib/card/set/event.rb +2 -2
  69. data/lib/card/set/format/abstract_format/view_definition.rb +1 -1
  70. data/lib/card/set/format/haml_paths.rb +1 -1
  71. data/lib/card/set/format.rb +4 -4
  72. data/lib/card/set/helpers.rb +4 -4
  73. data/lib/card/set/i18n_scanner.rb +23 -22
  74. data/lib/card/set/i18n_scope.rb +4 -3
  75. data/lib/card/set/pattern/all.rb +1 -1
  76. data/lib/card/set/pattern/base.rb +6 -3
  77. data/lib/card/set/pattern/class_methods.rb +1 -1
  78. data/lib/card/set/pattern.rb +1 -1
  79. data/lib/card/set/required_field.rb +3 -0
  80. data/lib/card/set/trait.rb +6 -1
  81. data/lib/card/subcards/all.rb +12 -4
  82. data/lib/card/view/cache/cache_action.rb +9 -3
  83. data/lib/card/view/cache.rb +17 -15
  84. data/lib/card/view/classy.rb +5 -5
  85. data/lib/card/view/options/key_lists.rb +1 -0
  86. data/lib/card/view/options/voo_api.rb +2 -2
  87. data/lib/card/view/options.rb +1 -0
  88. data/lib/card/view.rb +1 -1
  89. data/lib/cardio/command/application.rb +1 -1
  90. data/lib/cardio/command/custom.rb +7 -6
  91. data/lib/cardio/command/rake_command.rb +3 -2
  92. data/lib/cardio/command/rspec_command.rb +1 -0
  93. data/lib/cardio/generators/deck_generator_loader.rb +1 -1
  94. data/lib/cardio/generators.rb +4 -3
  95. data/lib/cardio/migration/port.rb +2 -0
  96. data/lib/cardio/migration/stamp.rb +1 -0
  97. data/lib/cardio/migration/transform.rb +1 -0
  98. data/lib/cardio/migration.rb +2 -0
  99. data/lib/cardio/mod/class_methods.rb +1 -2
  100. data/lib/cardio/mod/dirs.rb +2 -4
  101. data/lib/cardio/mod/eat/edibles.rb +8 -6
  102. data/lib/cardio/mod/eat.rb +7 -9
  103. data/lib/cardio/mod/load_strategy/set_binding_magic.rb +1 -1
  104. data/lib/cardio/mod/load_strategy/tmp_files.rb +3 -2
  105. data/lib/cardio/mod/load_strategy.rb +1 -0
  106. data/lib/cardio/mod/loader/set_pattern_loader.rb +4 -0
  107. data/lib/cardio/mod/loader/set_template.rb +14 -4
  108. data/lib/cardio/mod/loader.rb +2 -2
  109. data/lib/cardio/mod/sow/card_source.rb +1 -1
  110. data/lib/cardio/mod/sow/remote_source.rb +32 -0
  111. data/lib/cardio/mod/sow.rb +10 -10
  112. data/lib/cardio/railtie.rb +1 -0
  113. data/lib/cardio/script_loader.rb +1 -1
  114. data/lib/cardio/seed.rb +2 -2
  115. data/lib/cardio/utils.rb +1 -1
  116. data/lib/cardio/version.rb +2 -1
  117. data/lib/cardio.rb +3 -0
  118. data/lib/generators/deck/templates/config.ru.erb +1 -1
  119. data/mod/core/config/locales/de.yml +1 -1
  120. data/mod/core/config/locales/en.yml +2 -1
  121. data/mod/core/data/fixtures/real/cards.yml +1 -1
  122. data/mod/core/data/real.yml +1 -1
  123. data/mod/core/data/recode.yml +1 -0
  124. data/mod/core/data/schema/20141001105348_move_revisions_to_actions.rb +2 -2
  125. data/mod/core/data/schema/20241017160402_unique_codename.rb +8 -0
  126. data/mod/core/data/transform/20150724123438_update_file_and_image_cards.rb +1 -1
  127. data/mod/core/lib/tasks/card/export.rake +28 -0
  128. data/mod/core/lib/tasks/card/migrate.rake +3 -3
  129. data/mod/core/lib/tasks/card/mod.rake +1 -1
  130. data/mod/core/lib/tasks/card/seed.rake +2 -1
  131. data/mod/core/lib/tasks/card.rake +48 -16
  132. data/mod/core/set/all/admin.rb +1 -2
  133. data/mod/core/set/all/assign_attributes.rb +3 -2
  134. data/mod/core/set/all/codename.rb +7 -1
  135. data/mod/core/set/all/debug.rb +3 -3
  136. data/mod/core/set/all/initialize.rb +1 -0
  137. data/mod/core/set/all/states.rb +13 -16
  138. data/mod/core/set/all/type.rb +3 -1
  139. data/mod/core/set/all/utils.rb +0 -1
  140. data/mod/core/set/self/admin.rb +2 -1
  141. data/mod/core/set/self/autoname.rb +1 -1
  142. data/mod/core/set/self/mod.rb +4 -4
  143. data/mod/core/set/self/trash.rb +1 -1
  144. data/mod/core/set/type/mod.rb +18 -15
  145. data/mod/core/set_pattern/09_self.rb +4 -0
  146. data/mod/core/spec/set/all/admin_spec.rb +1 -1
  147. data/mod/core/spec/set/all/trash_spec.rb +9 -9
  148. metadata +42 -29
@@ -21,10 +21,33 @@ class Card
21
21
  def reset_session
22
22
  if session.is_a? Hash
23
23
  @session = {}
24
- else
25
- controller&.reset_session
24
+ elsif request
25
+ update_session_options drop: false
26
+ controller.reset_session
27
+ # destroy_cookie unless Cardio.config.allow_anonymous_cookies
26
28
  end
27
29
  end
30
+
31
+ def update_session_options drop: nil
32
+ return unless request
33
+ return if Cardio.config.allow_anonymous_cookies
34
+
35
+ request.session_options[:drop] = drop.nil? ? !Auth.signed_in? : drop
36
+ end
37
+
38
+ # private
39
+
40
+ # FIXME: not working
41
+ # the response generally works to destroy a cookie, but
42
+ # the deletion doesn't appear to work in a redirect. Since signing out
43
+ # has a redirect response, we're still left with a cookie
44
+ # def destroy_cookie
45
+ # app = Cardio.application
46
+ # app_name = app.class.name ? app.railtie_name.chomp("_application") : ""
47
+ # expire_in_past = "expires=Thu, 01 Jan 1970 00:00:00 GMT;"
48
+ # controller.response.set_header "SET-COOKIE",
49
+ # "_#{app_name}_session=deleted; #{expire_in_past}"
50
+ # end
28
51
  end
29
52
  end
30
53
  end
data/lib/card/error.rb CHANGED
@@ -78,6 +78,7 @@ class Card
78
78
  class BadQuery < UserError
79
79
  end
80
80
 
81
+ # error with url
81
82
  class BadAddress < UserError
82
83
  self.status_code = 404
83
84
  self.view = :bad_address
@@ -36,7 +36,7 @@ class Card
36
36
  end
37
37
 
38
38
  def needs_prep?
39
- return unless card.present?
39
+ return false unless card.present?
40
40
 
41
41
  !(skip_modules? || card.patterns?)
42
42
  end
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  class Format
3
+ # permissions and errors in card format classes
3
4
  module Error
4
5
  def ok? task
5
6
  task = :create if task == :update && card.new_card?
@@ -16,8 +17,8 @@ class Card
16
17
 
17
18
  def view_for_unknown setting_view
18
19
  if main? && voo.root?
19
- root.error_status = 404
20
- :not_found
20
+ root.error_status = page_status_for_unknown
21
+ page_view_for_unknown
21
22
  else
22
23
  setting_view || :unknown
23
24
  end
@@ -38,11 +39,21 @@ class Card
38
39
  yield
39
40
  end
40
41
 
42
+ private
43
+
41
44
  def rescue_view e, view
42
45
  method = loud_error? ? :loud_error : :quiet_error
43
46
  send method, e, view
44
47
  end
45
48
 
49
+ def page_status_for_unknown
50
+ 404
51
+ end
52
+
53
+ def page_view_for_unknown
54
+ :not_found
55
+ end
56
+
46
57
  def error_cardname _exception
47
58
  if card&.name.present?
48
59
  safe_name
@@ -1,5 +1,7 @@
1
1
  class Card
2
2
  class Format
3
+ # missing methods may be render calls or action view methods
4
+ # these methods sort that out
3
5
  module MethodDelegation
4
6
  RENDER_METHOD_RE =
5
7
  /^
@@ -40,7 +42,7 @@ class Card
40
42
  if (match = api_render? method)
41
43
  api_render match, opts
42
44
  else
43
- delegate_to_action_view(method, opts, proc) { yield }
45
+ delegate_to_action_view method, opts, &proc
44
46
  end
45
47
  end
46
48
 
@@ -66,9 +68,9 @@ class Card
66
68
  end
67
69
  end
68
70
 
69
- def delegate_to_action_view method, opts, proc
70
- proc = proc { |*a| raw yield(*a) } if proc
71
- response = action_view.send method, *opts, &proc
71
+ def delegate_to_action_view method, opts, &old_proc
72
+ new_proc = proc { |*a| raw yield(*a) } if old_proc
73
+ response = action_view.send method, *opts, &new_proc
72
74
  response.is_a?(String) ? action_view.raw(response) : response
73
75
  end
74
76
  end
@@ -1,5 +1,7 @@
1
1
  class Card
2
2
  class Format
3
+ # handles format registry, tracking which formats (html, css, json, etc) are
4
+ # available
3
5
  module Registration
4
6
  def register format
5
7
  registered << format.to_s
@@ -7,11 +9,11 @@ class Card
7
9
  end
8
10
 
9
11
  def new card, opts={}
10
- if self != Format
11
- super
12
- else
12
+ if self == Format
13
13
  klass = format_class opts
14
14
  self == klass ? super : klass.new(card, opts)
15
+ else
16
+ super
15
17
  end
16
18
  end
17
19
 
@@ -41,6 +41,57 @@ class Card
41
41
  add_debug_info view, method, rendered
42
42
  end
43
43
 
44
+ def pretty_path source_location
45
+ "#{source_location.first.gsub(%r{^.+mod\d+-([^/]+)},
46
+ '\1: ')}:#{source_location.second}"
47
+ end
48
+
49
+ # see {Abstract::Format}
50
+ # (:default), :yes, :deep, :always, :never
51
+ def view_cache_setting view
52
+ voo&.cache || view_setting(:cache, view) || :default
53
+ end
54
+
55
+ def view_setting setting_name, view
56
+ try Card::Set::Format.view_setting_method_name(view, setting_name)
57
+ end
58
+
59
+ def stub_render cached_content
60
+ return cached_content if Cardio.config.view_cache == :debug
61
+
62
+ # stub_debugging do
63
+ expand_stubs cached_content
64
+ # end
65
+ end
66
+
67
+ def view_method view
68
+ unless supports_view? view
69
+ raise Card::Error::UserError, unsupported_view_error_message(view)
70
+ end
71
+
72
+ method Card::Set::Format.view_method_name(view)
73
+ end
74
+
75
+ def supports_view? view
76
+ respond_to? Card::Set::Format.view_method_name(view)
77
+ end
78
+
79
+ def current_view view
80
+ old_view = @current_view
81
+ @current_view = view
82
+ yield
83
+ ensure
84
+ @current_view = old_view
85
+ end
86
+
87
+ def stub_nest stub_hash
88
+ prepare_stub_nest(stub_hash) do |stub_card, view_opts|
89
+ nest stub_card, view_opts, stub_hash[:format_opts]
90
+ end
91
+ end
92
+
93
+ private
94
+
44
95
  def wrap_and_render view
45
96
  current_view(view) { with_wrapper { final_render view } }
46
97
  rescue StandardError => e
@@ -64,27 +115,6 @@ class Card
64
115
  Env.params[:debug] == "view"
65
116
  end
66
117
 
67
- def pretty_path source_location
68
- "#{source_location.first.gsub(%r{^.+mod\d+-([^/]+)},
69
- '\1: ')}:#{source_location.second}"
70
- end
71
-
72
- # see {Abstract::Format}
73
- # (:default), :yes, :deep, :always, :never
74
- def view_cache_setting view
75
- voo&.cache || view_setting(:cache, view) || :default
76
- end
77
-
78
- def view_setting setting_name, view
79
- try Card::Set::Format.view_setting_method_name(view, setting_name)
80
- end
81
-
82
- def stub_render cached_content
83
- # stub_debugging do
84
- expand_stubs cached_content
85
- # end
86
- end
87
-
88
118
  # def stub_debugging
89
119
  # result = yield
90
120
  # if Rails.env.development? && result.is_a?(String) && result =~ /StUb/
@@ -118,32 +148,6 @@ class Card
118
148
  conto.to_s
119
149
  end
120
150
  end
121
-
122
- def view_method view
123
- unless supports_view? view
124
- raise Card::Error::UserError, unsupported_view_error_message(view)
125
- end
126
-
127
- method Card::Set::Format.view_method_name(view)
128
- end
129
-
130
- def supports_view? view
131
- respond_to? Card::Set::Format.view_method_name(view)
132
- end
133
-
134
- def current_view view
135
- old_view = @current_view
136
- @current_view = view
137
- yield
138
- ensure
139
- @current_view = old_view
140
- end
141
-
142
- def stub_nest stub_hash
143
- prepare_stub_nest(stub_hash) do |stub_card, view_opts|
144
- nest stub_card, view_opts, stub_hash[:format_opts]
145
- end
146
- end
147
151
  end
148
152
  end
149
153
  end
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  class Format
3
+ # handles view wrapping, including with layouts and slots
3
4
  module Wrapper
4
5
  def with_wrapper
5
6
  if voo.layout.present?
data/lib/card/lexicon.rb CHANGED
@@ -18,9 +18,12 @@ class Card
18
18
  # param name [String]
19
19
  # @return [Integer]
20
20
  def id name
21
- return unless name.present?
21
+ return if name.blank?
22
22
 
23
- (lex = name_to_lex name.to_name) && lex_to_id(lex)
23
+ name = name.to_name
24
+ return if name.relative_fragment?
25
+
26
+ (lex = name_to_lex name) && lex_to_id(lex)
24
27
  end
25
28
 
26
29
  def cache
data/lib/card/mailer.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "open-uri"
4
4
 
5
5
  class Card
6
+ # extends ActionMailer with card config
6
7
  class Mailer < ActionMailer::Base
7
8
  class << self
8
9
  def new_mail *args, &block
@@ -14,20 +15,6 @@ class Card
14
15
  end
15
16
  end
16
17
 
17
- def layout message
18
- <<-HTML
19
- <!DOCTYPE html>
20
- <html>
21
- <head>
22
- <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
23
- </head>
24
- <body>
25
- #{message}
26
- </body>
27
- </html>
28
- HTML
29
- end
30
-
31
18
  def defaults_from_config
32
19
  (Card.config.email_defaults || {}).symbolize_keys.tap do |defaults|
33
20
  defaults[:return_path] ||= defaults[:from] if defaults[:from]
@@ -5,7 +5,7 @@ class Card
5
5
  module Parts
6
6
  def left *args
7
7
  case
8
- when simple? then nil
8
+ when simple? then nil
9
9
  when superleft then superleft
10
10
  when name_is_changing? && name.to_name.trunk_name == name_before_act.to_name
11
11
  nil # prevent recursion when, eg, renaming A+B to A+B+C
data/lib/card/name/all.rb CHANGED
@@ -8,6 +8,7 @@ class Card
8
8
  # TODO: use delegations and include more name functions
9
9
  delegate :simple?, :compound?, :junction?, to: :name
10
10
  attr_reader :supercard
11
+
11
12
  def name
12
13
  @name ||= left_id ? Lexicon.lex_to_name([left_id, right_id]) : super.to_name
13
14
  end
@@ -57,6 +58,10 @@ class Card
57
58
  end
58
59
  end
59
60
 
61
+ def id_string
62
+ "~#{id}"
63
+ end
64
+
60
65
  def key= newkey
61
66
  return if newkey == key
62
67
 
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  class Name
3
+ # variants of card names
3
4
  module NameVariants
4
5
  @@variant_methods = %i[capitalize singularize pluralize titleize
5
6
  downcase upcase swapcase reverse succ]
@@ -19,13 +19,12 @@ class Card
19
19
  end
20
20
 
21
21
  def table_alias
22
- @table_alias ||= begin
22
+ @table_alias ||=
23
23
  if fasten == :direct
24
24
  @superquery.table_alias
25
25
  else
26
26
  "#{table_prefix}#{root.table_seq}#{@table_suffix}"
27
27
  end
28
- end
29
28
  end
30
29
 
31
30
  def table_seq
@@ -107,7 +107,7 @@ class Card
107
107
  end
108
108
 
109
109
  def list_of_ids? val
110
- return unless val.is_a? Array
110
+ return false unless val.is_a? Array
111
111
 
112
112
  !val.find { |v| !id_from_val v }
113
113
  end
@@ -71,10 +71,10 @@ class Card
71
71
  end
72
72
 
73
73
  def context
74
- if !@context.nil?
75
- @context
76
- else
74
+ if @context.nil?
77
75
  @context = superquery ? superquery.context : ""
76
+ else
77
+ @context
78
78
  end
79
79
  end
80
80
 
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  module Query
3
+ # query-related methods with which to extend Card class
3
4
  module CardClass
4
5
  def search spec, comment=nil, &block
5
6
  results = ::Card::Query.run(spec, comment)
@@ -4,7 +4,7 @@ class Card
4
4
  # interpret CQL attributes that relate multiple cards
5
5
  # each method below corresponds to a relational CQL term
6
6
  #
7
- # NOTE: methods using "restrict" can be executed without
7
+ # NOTE: methods using "restrict" can be executed without
8
8
  # tying in an additional query if the val in question can be
9
9
  # reduced to an id.
10
10
  module RelationalAttributes
@@ -38,7 +38,7 @@ class Card
38
38
  case
39
39
  when respond_to?(:"#{retrn}_result") then :"#{retrn}_result"
40
40
  when retrn.match?(/id$/) then :id_result
41
- when retrn.match?(/_\w+/) then :name_result
41
+ when retrn.match?(/^_\w+/) then :name_result
42
42
  when retrn == "key" then :key_result
43
43
  else :default_result
44
44
  end
@@ -52,6 +52,10 @@ class Card
52
52
  record[field]
53
53
  end
54
54
 
55
+ def content_result record, _pattern
56
+ record["db_content"]
57
+ end
58
+
55
59
  def id_result record, field
56
60
  record[field].to_i
57
61
  end
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  module Query
3
+ # shared methods for query clauses
3
4
  module Clause
4
5
  # attr_accessor :clause
5
6
 
@@ -44,10 +44,10 @@ class Card
44
44
  end
45
45
 
46
46
  def side
47
- if !@side.nil?
48
- @side.to_s.upcase
49
- else
47
+ if @side.nil?
50
48
  @side = inside_or? ? "LEFT" : nil
49
+ else
50
+ @side.to_s.upcase
51
51
  end
52
52
  end
53
53
 
@@ -24,6 +24,7 @@ class Card
24
24
  @fields = fields
25
25
  @tables = tables
26
26
  @joins = joins
27
+ @indexes = indexes
27
28
  @where = where
28
29
  @group = group
29
30
  @order = order
@@ -33,7 +34,8 @@ class Card
33
34
 
34
35
  def to_s
35
36
  [
36
- comment, select, from, @joins, @where, @group, @order, @limit_and_offset
37
+ comment, select, from,
38
+ @joins, @indexes, @where, @group, @order, @limit_and_offset
37
39
  ].compact.join " "
38
40
  end
39
41
 
@@ -103,6 +105,10 @@ class Card
103
105
  end
104
106
  end
105
107
 
108
+ def indexes
109
+ "USE INDEX (#{Array.wrap(@mods[:index]).join ', '})" if @mods[:index]
110
+ end
111
+
106
112
  def full_syntax
107
113
  @query.full? ? yield : return
108
114
  end
data/lib/card/query.rb CHANGED
@@ -83,7 +83,7 @@ class Card
83
83
  # "dir" is DEPRECATED in favor of sort_dir
84
84
  # "sort" is DEPRECATED in favor of sort_by, except in cases where sort's value
85
85
  # is a hash
86
- MODIFIERS = %i[conj return sort_by sort_as sort_dir sort dir group limit offset]
86
+ MODIFIERS = %i[conj return index sort_by sort_as sort_dir sort dir group limit offset]
87
87
  .each_with_object({}) { |v, h| h[v] = nil }
88
88
 
89
89
  OPERATORS =
@@ -1,13 +1,12 @@
1
1
  class Card
2
2
  class Reference < Cardio::Record
3
- module All
4
- # frozen_string_literal: true
5
-
6
- # Cards can refer to other cards in their content, eg via links and nests.
7
- # The card that refers is the "referer", the card that is referred to is
8
- # the "referee". The reference itself has its own class (Card::Reference),
9
- # which handles id-based reference tracking.
3
+ # frozen_string_literal: true
10
4
 
5
+ # Cards can refer to other cards in their content, eg via links and nests.
6
+ # The card that refers is the "referer", the card that is referred to is
7
+ # the "referee". The reference itself has its own class (Card::Reference),
8
+ # which handles id-based reference tracking.
9
+ module All
11
10
  PARTIAL_REF_CODE = "P".freeze
12
11
 
13
12
  # cards that refer to self
@@ -1,5 +1,6 @@
1
1
  class Card
2
2
  module Rule
3
+ # a cache of all card rules in the deck
3
4
  class Cache
4
5
  class_attribute :sql, :cache_key
5
6
 
@@ -1,5 +1,7 @@
1
1
  class Card
2
2
  module Rule
3
+ # a preference is a user-specific rule.
4
+ # This caches all preferences in the deck
3
5
  class PreferenceCache < Cache
4
6
  self.sql = %(
5
7
  SELECT
@@ -1,5 +1,8 @@
1
1
  class Card
2
2
  module Rule
3
+ # the read rule cache, unlike the standard rule cache, is optimized for lookups
4
+ # based on the rules' values, because this is needed for high-performance
5
+ # permission-checking
3
6
  class ReadRuleCache < Cache
4
7
  self.sql = %(
5
8
  SELECT
@@ -14,7 +14,9 @@ class Card
14
14
  include SkipAndTrigger
15
15
 
16
16
  def event_applies? event
17
- return unless set_condition_applies? event.set_module, event.opts[:changing]
17
+ unless set_condition_applies? event.set_module, event.opts[:changing]
18
+ return false
19
+ end
18
20
 
19
21
  CONDITIONS.all? { |c| send "#{c}_condition_applies?", event, event.opts[c] }
20
22
  end
@@ -91,10 +93,10 @@ class Card
91
93
  def wrong_stage opts
92
94
  return false if director.stage_ok? opts
93
95
 
94
- if !stage
95
- "phase method #{method} called outside of event phases"
96
- else
96
+ if stage
97
97
  "#{opts.inspect} method #{method} called in stage #{stage}"
98
+ else
99
+ "phase method #{method} called outside of event phases"
98
100
  end
99
101
  end
100
102
 
@@ -1,6 +1,7 @@
1
1
  class Card
2
2
  module Set
3
3
  class Event
4
+ # handle card event callbacks
4
5
  module Callbacks
5
6
  def set_event_callbacks
6
7
  %i[before after around].each do |kind|
@@ -1,6 +1,7 @@
1
1
  class Card
2
2
  module Set
3
3
  class Event
4
+ # handle options available for event definition
4
5
  module Options
5
6
  def validate_conditions
6
7
  @opts.each do |key, val|
@@ -32,8 +33,8 @@ class Card
32
33
  return if invalid.empty?
33
34
 
34
35
  raise ArgumentError,
35
- "invalid option#{'s' if invalid.size > 1} '#{invalid}' "\
36
- "for condition '#{condition}' in event '#{@event}'"
36
+ "invalid option#{'s' if invalid.size > 1} '#{invalid}' " \
37
+ "for condition '#{condition}' in event '#{@event}'"
37
38
  end
38
39
 
39
40
  def invalid_condition_values condition, val
@@ -7,7 +7,7 @@ class Card
7
7
  :skip, # [Array] skip event(s) for all cards in act
8
8
  :skip_in_action, # [Array] skip event for just this card
9
9
  :trigger, # [Array] trigger event(s) for all cards in act
10
- :trigger_in_action, # [Array] trigger event for just this card
10
+ :trigger_in_action # [Array] trigger event for just this card
11
11
  ]
12
12
  attr_reader(*settings)
13
13
 
@@ -165,8 +165,8 @@ class Card
165
165
  end
166
166
 
167
167
  # one failed integration event should not harm others.
168
- def rescuing_integration
169
- Error.rescue_card(self) { yield }
168
+ def rescuing_integration &block
169
+ Error.rescue_card(self, &block)
170
170
  ensure
171
171
  true
172
172
  end
@@ -58,7 +58,7 @@ class Card
58
58
 
59
59
  views[mod][alias_to] || begin
60
60
  raise "cannot find #{alias_to} view in #{mod}; " \
61
- "failed to alias #{view} from #{self}"
61
+ "failed to alias #{view} from #{self}"
62
62
  end
63
63
  end
64
64
  end
@@ -46,7 +46,7 @@ class Card
46
46
  end
47
47
  end
48
48
 
49
- TMPSET_REGEXP = %r{^.*/tmp(sets)?/set/[\w-]+/mod\d{3}-(?<modname>[^/]+)}
49
+ TMPSET_REGEXP = %r{^.*/tmp(?:sets)?/set/[\w-]+/mod\d{3}-(?<modname>[^/]+)}
50
50
 
51
51
  def deep_source source
52
52
  return source unless tmp_files?
@@ -103,14 +103,14 @@ class Card
103
103
 
104
104
  # shortcut for {AbstractFormat#view} for when #view is called outside of a format
105
105
  # block
106
- def view *args, &block
107
- format { view(*args, &block) }
106
+ def view(...)
107
+ format { view(...) }
108
108
  end
109
109
 
110
110
  # shortcut for {AbstractFormat#before} for when #before is called outside of a
111
111
  # format block
112
- def before view, &block
113
- format { before view, &block }
112
+ def before(...)
113
+ format { before(...) }
114
114
  end
115
115
 
116
116
  private