card 1.101.2 → 1.101.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af639cc0367bf40d94b5f4f4b170898aecf1fabd9554613cd6ead266c3460758
4
- data.tar.gz: 156bdc8fb46acd5d05ee77e371dc3baebc51ab038064099ac7489106fdf150db
3
+ metadata.gz: faefffa729032513970c6385b5d327791a5126ff3b3b8973a003c46bef3e7248
4
+ data.tar.gz: f4529445aae06fa4b7fac2aef3de056d3beaaa75c2a0f609b1bce93fa3cf3cba
5
5
  SHA512:
6
- metadata.gz: 686e3a3cf69d047756b65f65868c55403493bf94f8e77ce9cc71cf7a1eccb931096cdc0f0fbe593827133bb525ef7132dc1be8ad6fb00c7d8492b273e31b8d9d
7
- data.tar.gz: 6f0db4e8c51a8b7e4f03fc184ac134747443c0f31f58fc2e8609a065b38e653c62d22fbf99d3d6cf31f3979cdbd0fc699a0e120371d8e6d5827ca204857cc369
6
+ metadata.gz: e654fd3876906be1fb56802fa438a536ab6b3c22d29b6485f01fdadbe254cf3154abea3489d05bef6945e76a162002f61c69d05ce693ebbba3ecf4dcfa1a3dbc
7
+ data.tar.gz: 25d8c4b240631bb7b21cf7d6c070196ad06ad5a8829385deb9cdb9bf4aeeebb68981efcf39872a09349e734f367b10053b2d9e975fb33be1e0dfc1c4aabad241
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.2
1
+ 0.11.3
@@ -80,6 +80,8 @@ en:
80
80
  # deny_verb_name: You don't have permission to %{verb} %{name}
81
81
  # deny_verb_this: You don't have permission to %{verb} this
82
82
  # error_cant_delete_child: "can't delete %{child_name}: %{message}"
83
+
84
+
83
85
  error_code_in_use: codename %{codename} already in use
84
86
  error_hard_templated: can't be changed because %{name} is hard templated to %{type_name}
85
87
  error_indestructible: "%{name} is an indestructible rule"
@@ -231,7 +233,7 @@ en:
231
233
  discuss: discuss
232
234
  edit: edit
233
235
  error_message: Error message (visible to admin only)
234
- error_rendering: error rendering
236
+ error_rendering: "Error rendering: %{cardname} (%{view} view)"
235
237
  exception_not_set_path: "not a set path: %{path}"
236
238
  invalid_json: invalid json
237
239
  label_select: Select
@@ -69,7 +69,7 @@ class RailsInflectionUpdates < Cardio::Migration::Core
69
69
  end
70
70
  end
71
71
 
72
- cards_with_css = Card.search type: %w(in html css scss)
72
+ cards_with_css = Card.search type: %w[in html css scss]
73
73
  cards_with_css.each do |card|
74
74
  new_content = card.db_content
75
75
  content_changed = false
@@ -2,7 +2,8 @@ class Card
2
2
  module Env
3
3
  # Success objects
4
4
  class Success
5
- include Card::Env::Location
5
+ include Location
6
+ include Target
6
7
 
7
8
  attr_accessor :redirect, :name, :name_context, :reload
8
9
  attr_writer :params, :card
@@ -15,23 +16,20 @@ class Card
15
16
  self << normalize_success_args(success_args)
16
17
  end
17
18
 
19
+ def to_url name_context=@name_context
20
+ case (target = target(name_context))
21
+ when Card
22
+ target.format.path params
23
+ else
24
+ target
25
+ end
26
+ end
27
+
18
28
  def in_context name_context
19
29
  self.name_context = name_context
20
30
  self
21
31
  end
22
32
 
23
- def normalize_success_args success_args
24
- case success_args
25
- when nil
26
- self.mark = "_self"
27
- {}
28
- when ActionController::Parameters
29
- success_args.to_unsafe_h
30
- else
31
- success_args
32
- end
33
- end
34
-
35
33
  def << value
36
34
  if value.is_a? Hash
37
35
  apply value
@@ -44,75 +42,6 @@ class Card
44
42
  @reload.to_s == "true"
45
43
  end
46
44
 
47
- # TODO: refactor to use cardish
48
- def mark= value
49
- case value
50
- when Integer then @id = value
51
- when String then @name = value
52
- when Card then @card = value
53
- else
54
- self.target = value
55
- end
56
- end
57
-
58
- # @deprecated
59
- def id= id
60
- # for backwards compatibility use mark here.
61
- # id was often used for the card name
62
- self.mark = id
63
- end
64
-
65
- def type= type
66
- @new_args[:type] = type
67
- end
68
-
69
- def type_id= type_id
70
- @new_args[:type_id] = type_id.to_i
71
- end
72
-
73
- def content= content
74
- @new_args[:content] = content
75
- end
76
-
77
- def target= value
78
- @id = @name = @card = nil
79
- @target = process_target value
80
- end
81
-
82
- def process_target value
83
- case value
84
- when "" then ""
85
- when "*previous", :previous then :previous
86
- when %r{^(http|/)} then value
87
- when /^REDIRECT:\s*(.+)/
88
- @redirect = true
89
- process_target Regexp.last_match(1)
90
- else self.mark = value
91
- end
92
- end
93
-
94
- def apply hash
95
- hash.each_pair do |key, value|
96
- self[key] = value
97
- end
98
- end
99
-
100
- def card name_context=@name_context
101
- if @card
102
- @card
103
- elsif @id
104
- Card.fetch @id
105
- elsif @name
106
- Card.fetch @name.to_name.absolute(name_context), new: @new_args
107
- end
108
- end
109
-
110
- def target name_context=@name_context
111
- card(name_context) ||
112
- (@target == :previous ? Card::Env.previous_location : @target) ||
113
- Card.fetch(name_context)
114
- end
115
-
116
45
  def []= key, value
117
46
  if respond_to? "#{key}="
118
47
  send "#{key}=", value
@@ -139,32 +68,46 @@ class Card
139
68
  @params.marshal_dump
140
69
  end
141
70
 
142
- def raw_params
143
- @params
71
+ def session
72
+ Card::Env.session
144
73
  end
145
74
 
146
- def to_url name_context=@name_context
147
- case (target = target(name_context))
148
- when Card
149
- target.format.path params
150
- else
151
- target
152
- end
75
+ private
76
+
77
+ def respond_to_missing? method, _include_private=false
78
+ method.match?(/^(\w+)=?$/) || super
153
79
  end
154
80
 
155
81
  def method_missing method, *args
156
- case method
157
- when /^(\w+)=$/
158
- self[Regexp.last_match(1).to_sym] = args[0]
159
- when /^(\w+)$/
160
- self[Regexp.last_match(1).to_sym]
82
+ if (m = method.match(/^(\w+(=)?)/))
83
+ infer_bracket m[1].to_sym, m[2], args[0]
161
84
  else
162
85
  super
163
86
  end
164
87
  end
165
88
 
166
- def session
167
- Card::Env.session
89
+ def infer_bracket method, assign, val
90
+ args = [method]
91
+ args << val if assign
92
+ @params.send(*args)
93
+ end
94
+
95
+ def apply hash
96
+ hash.each_pair do |key, value|
97
+ self[key] = value
98
+ end
99
+ end
100
+
101
+ def normalize_success_args success_args
102
+ case success_args
103
+ when nil
104
+ self.mark = "_self"
105
+ {}
106
+ when ActionController::Parameters
107
+ success_args.to_unsafe_h
108
+ else
109
+ success_args
110
+ end
168
111
  end
169
112
  end
170
113
  end
@@ -0,0 +1,75 @@
1
+ class Card
2
+ module Env
3
+ class Success
4
+ # The success "target" is the destination upon success.
5
+ #
6
+ # @card, @name, @id, etc all refer to the target card
7
+ module Target
8
+ def target= value
9
+ @id = @name = @card = nil
10
+ @target = process_target value
11
+ end
12
+
13
+ def target name_context=@name_context
14
+ card(name_context) ||
15
+ (@target == :previous ? Card::Env.previous_location : @target) ||
16
+ Card.fetch(name_context)
17
+ end
18
+
19
+ # TODO: refactor to use cardish
20
+ def mark= value
21
+ case value
22
+ when Integer then @id = value
23
+ when String then @name = value
24
+ when Card then @card = value
25
+ else
26
+ self.target = value
27
+ end
28
+ end
29
+
30
+ # @deprecated
31
+ def id= id
32
+ # for backwards compatibility use mark here.
33
+ # id was often used for the card name
34
+ self.mark = id
35
+ end
36
+
37
+ def type= type
38
+ @new_args[:type] = type
39
+ end
40
+
41
+ def type_id= type_id
42
+ @new_args[:type_id] = type_id.to_i
43
+ end
44
+
45
+ def content= content
46
+ @new_args[:content] = content
47
+ end
48
+
49
+ def card name_context=@name_context
50
+ if @card
51
+ @card
52
+ elsif @id
53
+ Card.fetch @id
54
+ elsif @name
55
+ Card.fetch @name.to_name.absolute(name_context), new: @new_args
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def process_target value
62
+ case value
63
+ when "" then ""
64
+ when "*previous", :previous then :previous
65
+ when %r{^(http|/)} then value
66
+ when /^REDIRECT:\s*(.+)/
67
+ @redirect = true
68
+ process_target Regexp.last_match(1)
69
+ else self.mark = value
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -80,7 +80,7 @@ class Card
80
80
 
81
81
  def find_set_path backtrace
82
82
  re = %r{(?<!card)/set/}
83
- backtrace.find { |line| line =~ re }.tap do |path|
83
+ backtrace.find { |line| line.match?(re) }.tap do |path|
84
84
  return nil unless path
85
85
  end
86
86
  end
@@ -1,7 +1,6 @@
1
1
  class Card
2
2
  module Set
3
3
  # API to inherit other sets and their formats
4
-
5
4
  module Inheritance
6
5
 
7
6
  # include a set module and all its format modules
@@ -66,15 +65,19 @@ class Card
66
65
 
67
66
  # iterate through each format associated with a set
68
67
  def each_format set
69
- set_type = set.abstract_set? ? :abstract : :nonbase
70
- format_type = "#{set_type}_format".to_sym
71
- modules[format_type].each_pair do |format, set_format_mod_hash|
72
- next unless (format_mods = set_format_mod_hash[set.shortname])
68
+ each_format_with_mods set do |format, mods_for_set|
69
+ next unless (format_mods = mods_for_set[set.shortname])
73
70
 
74
71
  yield format, format_mods
75
72
  end
76
73
  end
77
74
 
75
+ def each_format_with_mods set
76
+ set_type = set.abstract_set? ? :abstract : :nonbase
77
+ format_type = "#{set_type}_format".to_sym
78
+ modules[format_type].each_pair { |*args| yield(*args) }
79
+ end
80
+
78
81
  def applicable_format? format, except, only
79
82
  format_sym = Card::Format.format_sym format
80
83
  return false if except && Array(except).include?(format_sym)
@@ -24,9 +24,7 @@ class Card
24
24
  modules[:base] << set_module
25
25
  else
26
26
  set_type = set_module.abstract_set? ? :abstract : :nonbase
27
- # made ready for dynamic loading via #include_set_modules
28
- modules[set_type][set_module.shortname] ||= []
29
- modules[set_type][set_module.shortname] << set_module
27
+ register_set_of_type set_module, set_type
30
28
  end
31
29
  end
32
30
 
@@ -44,19 +42,17 @@ class Card
44
42
  # Format class
45
43
  # 'nonbase modules' are included dynamically on singleton_classes
46
44
  def process_base_modules
47
- return unless modules[:base].present?
45
+ base_modules = modules[:base]
46
+ return unless base_modules.present?
48
47
 
49
- Card.add_set_modules modules[:base]
50
- modules[:base_format].each do |format_class, modules_list|
51
- format_class.add_set_modules modules_list
52
- end
53
- modules[:base].clear
54
- modules[:base_format].clear
48
+ Card.add_set_modules base_modules
49
+ process_base_format_modules modules[:base_format]
50
+ base_modules.clear
55
51
  end
56
52
 
57
53
  def clean_empty_modules
58
54
  clean_empty_module_from_hash modules[:nonbase]
59
- modules[:nonbase_format].values.each do |hash|
55
+ modules[:nonbase_format].each_value do |hash|
60
56
  clean_empty_module_from_hash hash
61
57
  end
62
58
  end
@@ -67,6 +63,23 @@ class Card
67
63
  hash.delete mod_name if modlist.empty?
68
64
  end
69
65
  end
66
+
67
+ private
68
+
69
+ # makes sets ready for dynamic loading via #include_set_modules
70
+ def register_set_of_type set_module, set_type
71
+ mods = modules[set_type]
72
+ key = set_module.shortname
73
+ mods[key] ||= []
74
+ mods[key] << set_module
75
+ end
76
+
77
+ def process_base_format_modules base_format_modules
78
+ base_format_modules.each do |format_class, modules_list|
79
+ format_class.add_set_modules modules_list
80
+ end
81
+ base_format_modules.clear
82
+ end
70
83
  end
71
84
  end
72
85
  end
@@ -3,60 +3,7 @@ class Card
3
3
  class Pattern
4
4
  # class from which set patterns inherit
5
5
  class Base
6
- class << self
7
- attr_accessor :pattern_code, :pattern_id, :junction_only,
8
- :assigns_type, :anchorless
9
- attr_writer :anchor_parts_count
10
-
11
- def new card
12
- super if pattern_applies? card
13
- end
14
-
15
- def register pattern_code, opts={}
16
- if (self.pattern_id = Card::Codename.id(pattern_code))
17
- self.pattern_code = pattern_code
18
- Card.set_patterns.insert opts.delete(:index).to_i, self
19
- self.anchorless = !respond_to?(:anchor_name)
20
- opts.each { |key, val| send "#{key}=", val }
21
- else
22
- warn "no codename for pattern_code #{pattern_code}"
23
- end
24
- end
25
-
26
- def junction_only?
27
- junction_only == true
28
- end
29
-
30
- def anchorless?
31
- anchorless
32
- end
33
-
34
- def pattern
35
- Card.fetch(pattern_id, skip_modules: true).name
36
- end
37
-
38
- def pattern_applies? card
39
- junction_only? ? card.name.junction? : true
40
- end
41
-
42
- def anchor_parts_count
43
- @anchor_parts_count ||= (anchorless? ? 0 : 1)
44
- end
45
-
46
- def module_key anchor_codes
47
- return pattern_code.to_s.camelize if anchorless?
48
- return unless anchor_codes # is this not an error?
49
-
50
- ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::"
51
- end
52
-
53
- # label for set pattern if no anchor is given
54
- def generic_label
55
- label nil
56
- end
57
- end
58
-
59
- # Instance methods
6
+ extend ClassMethods
60
7
 
61
8
  def initialize card
62
9
  return if self.class.anchorless?
@@ -134,24 +81,6 @@ class Card
134
81
  end
135
82
  end
136
83
  end
137
-
138
- module Helper
139
- private
140
-
141
- def left_type card
142
- card.superleft&.type_name || quick_type(card.name.left_name)
143
- end
144
-
145
- def quick_type name
146
- if name.present?
147
- card = Card.fetch name, skip_modules: true, new: {}
148
- card.include_set_modules if card.new? && name.to_name.junction?
149
- card&.type_name
150
- else
151
- "RichText"
152
- end
153
- end
154
- end
155
84
  end
156
85
  end
157
86
  end
@@ -0,0 +1,75 @@
1
+ class Card
2
+ module Set
3
+ class Pattern
4
+ # methods for Set::Pattern classes
5
+ module ClassMethods
6
+ attr_accessor :pattern_code, :pattern_id, :junction_only,
7
+ :assigns_type, :anchorless
8
+ attr_writer :anchor_parts_count
9
+
10
+ def new card
11
+ super if pattern_applies? card
12
+ end
13
+
14
+ def register pattern_code, opts={}
15
+ if (self.pattern_id = Card::Codename.id(pattern_code))
16
+ self.pattern_code = pattern_code
17
+ Card.set_patterns.insert opts.delete(:index).to_i, self
18
+ self.anchorless = !respond_to?(:anchor_name)
19
+ opts.each { |key, val| send "#{key}=", val }
20
+ else
21
+ warn "no codename for pattern_code #{pattern_code}"
22
+ end
23
+ end
24
+
25
+ def junction_only?
26
+ junction_only == true
27
+ end
28
+
29
+ def anchorless?
30
+ anchorless
31
+ end
32
+
33
+ def pattern
34
+ Card.fetch(pattern_id, skip_modules: true).name
35
+ end
36
+
37
+ def pattern_applies? card
38
+ junction_only? ? card.name.junction? : true
39
+ end
40
+
41
+ def anchor_parts_count
42
+ @anchor_parts_count ||= (anchorless? ? 0 : 1)
43
+ end
44
+
45
+ def module_key anchor_codes
46
+ return pattern_code.to_s.camelize if anchorless?
47
+ return unless anchor_codes # is this not an error?
48
+
49
+ ([pattern_code] + anchor_codes).map { |code| code.to_s.camelize }.join "::"
50
+ end
51
+
52
+ # label for set pattern if no anchor is given
53
+ def generic_label
54
+ label nil
55
+ end
56
+
57
+ private
58
+
59
+ def left_type card
60
+ card.superleft&.type_name || quick_type(card.name.left_name)
61
+ end
62
+
63
+ def quick_type name
64
+ if name.present?
65
+ card = Card.fetch name, skip_modules: true, new: {}
66
+ card.include_set_modules if card.new? && name.to_name.junction?
67
+ card&.type_name
68
+ else
69
+ "RichText"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -65,7 +65,7 @@ module Cardio
65
65
  # Add a mod to mod load paths
66
66
  def add_path mod_name, path=nil
67
67
  if @mods.include? mod_name
68
- raise Error,
68
+ raise Card::Error,
69
69
  "name conflict: mod with name \"#{mod_name}\" already loaded"
70
70
  end
71
71
  @mods << mod_name
@@ -80,7 +80,7 @@ module Cardio
80
80
  end
81
81
 
82
82
  def unknown_gem_mod! name
83
- raise Error, %(Unknown gem "#{name}". Make sure it is in your Gemfile.)
83
+ raise Card::Error, %(Unknown gem "#{name}". Make sure it is in your Gemfile.)
84
84
  end
85
85
 
86
86
  def add_gem_mod mod_name, mod_path
@@ -40,7 +40,6 @@ module Cardio
40
40
  def preamble_bits
41
41
  [module_comment,
42
42
  module_chain,
43
- "extend Card::Set::Pattern::Helper",
44
43
  "cattr_accessor :options",
45
44
  "class << self"]
46
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.101.2
4
+ version: 1.101.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-03-15 00:00:00.000000000 Z
13
+ date: 2021-04-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: cardname
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.11.2
21
+ version: 0.11.3
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.11.2
28
+ version: 0.11.3
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -543,6 +543,7 @@ files:
543
543
  - lib/card/env/serialization.rb
544
544
  - lib/card/env/slot_options.rb
545
545
  - lib/card/env/success.rb
546
+ - lib/card/env/success/target.rb
546
547
  - lib/card/error.rb
547
548
  - lib/card/fetch.rb
548
549
  - lib/card/fetch/results.rb
@@ -631,6 +632,7 @@ files:
631
632
  - lib/card/set/loader.rb
632
633
  - lib/card/set/pattern.rb
633
634
  - lib/card/set/pattern/base.rb
635
+ - lib/card/set/pattern/class_methods.rb
634
636
  - lib/card/set/required_field.rb
635
637
  - lib/card/set/trait.rb
636
638
  - lib/card/set/type.rb
@@ -1237,7 +1239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1237
1239
  - !ruby/object:Gem::Version
1238
1240
  version: '0'
1239
1241
  requirements: []
1240
- rubygems_version: 3.0.3
1242
+ rubygems_version: 3.1.4
1241
1243
  signing_key:
1242
1244
  specification_version: 4
1243
1245
  summary: a simple engine for emergent data structures