wagn 1.13.0.pre1 → 1.13.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/app/controllers/card_controller.rb +3 -3
  4. data/db/migrate_cards/20140307231621_user_data_to_cards.rb +5 -1
  5. data/lib/card.rb +5 -7
  6. data/lib/card/chunk.rb +1 -0
  7. data/lib/card/codename.rb +48 -31
  8. data/lib/card/env.rb +0 -1
  9. data/lib/card/exceptions.rb +3 -3
  10. data/lib/card/format.rb +89 -166
  11. data/lib/card/generators/set/USAGE +1 -1
  12. data/lib/card/loader.rb +1 -1
  13. data/lib/card/set.rb +196 -112
  14. data/lib/card/set_pattern.rb +37 -71
  15. data/lib/wagn/cache.rb +8 -7
  16. data/lib/wagn/commands.rb +1 -1
  17. data/lib/wagn/config/environments/development.rb +1 -1
  18. data/lib/wagn/config/initializers/paperclip.rb +1 -0
  19. data/lib/wagn/generators/wagn/templates/Gemfile +59 -55
  20. data/lib/wagn/location.rb +2 -2
  21. data/mods/core/formats/html_format.rb +2 -6
  22. data/mods/core/formats/text_format.rb +1 -1
  23. data/mods/core/set_patterns/01_all.rb +0 -5
  24. data/mods/core/set_patterns/02_all_plus.rb +1 -3
  25. data/mods/core/set_patterns/07_type_plus_right.rb +0 -1
  26. data/mods/core/sets/all/active_card.rb +1 -1
  27. data/mods/core/sets/all/name.rb +3 -2
  28. data/mods/core/sets/all/pattern.rb +9 -23
  29. data/mods/core/sets/all/phases.rb +27 -13
  30. data/mods/core/sets/all/rules.rb +3 -3
  31. data/mods/core/sets/all/templating.rb +5 -2
  32. data/mods/core/sets/all/tracked_attributes.rb +2 -1
  33. data/mods/core/sets/right/structure.rb +13 -0
  34. data/mods/{standard → core}/sets/type/plain_text.rb +0 -0
  35. data/mods/standard/formats/email_html_format.rb +1 -1
  36. data/mods/standard/lib/card/machine.rb +16 -12
  37. data/mods/standard/lib/card/machine_input.rb +1 -1
  38. data/mods/standard/sets/all/attach.rb +1 -1
  39. data/mods/standard/sets/all/base.rb +92 -94
  40. data/mods/standard/sets/all/follow.rb +1 -1
  41. data/mods/standard/sets/all/rich_html.rb +5 -3
  42. data/mods/standard/sets/all/rss.rb +12 -5
  43. data/mods/standard/sets/right/account.rb +1 -1
  44. data/mods/standard/sets/right/add_help.rb +3 -1
  45. data/mods/standard/sets/right/comment.rb +92 -3
  46. data/mods/standard/sets/right/create.rb +2 -87
  47. data/mods/standard/sets/right/default.rb +3 -2
  48. data/mods/standard/sets/right/delete.rb +2 -5
  49. data/mods/standard/sets/right/help.rb +3 -1
  50. data/mods/standard/sets/right/machine_output.rb +9 -7
  51. data/mods/standard/sets/right/read.rb +2 -5
  52. data/mods/standard/sets/right/style.rb +3 -2
  53. data/mods/standard/sets/right/update.rb +2 -5
  54. data/mods/standard/sets/rstar/rules.rb +0 -2
  55. data/mods/standard/sets/self/head.rb +2 -3
  56. data/mods/standard/sets/self/navbox.rb +0 -7
  57. data/mods/standard/sets/self/recent.rb +2 -2
  58. data/mods/standard/sets/self/search.rb +10 -3
  59. data/mods/standard/sets/self/signin.rb +3 -3
  60. data/mods/standard/sets/type/cardtype.rb +2 -2
  61. data/mods/standard/sets/type/coffee_script.rb +4 -4
  62. data/mods/standard/sets/type/css.rb +12 -4
  63. data/mods/standard/sets/type/image.rb +19 -19
  64. data/mods/standard/sets/type/java_script.rb +1 -1
  65. data/mods/standard/sets/type/layout_type.rb +3 -2
  66. data/mods/standard/sets/type/pointer.rb +3 -2
  67. data/mods/standard/sets/type/scss.rb +6 -34
  68. data/mods/standard/sets/type/search_type.rb +22 -16
  69. data/mods/standard/sets/type/set.rb +2 -2
  70. data/mods/standard/sets/type/setting.rb +2 -2
  71. data/mods/standard/sets/type/skin.rb +4 -18
  72. data/spec/controllers/card_controller_spec.rb +2 -2
  73. data/spec/lib/card/flexmail_spec.rb +1 -0
  74. data/spec/lib/card/format_spec.rb +9 -9
  75. data/spec/lib/card/loader_spec.rb +1 -2
  76. data/spec/lib/card/name_spec.rb +7 -1
  77. data/spec/lib/card/set_pattern_spec.rb +5 -5
  78. data/spec/mods/core/sets/all/pattern_spec.rb +0 -9
  79. data/spec/mods/core/sets/all/phases_spec.rb +2 -1
  80. data/spec/mods/standard/lib/machine_input_spec.rb +20 -4
  81. data/spec/mods/standard/lib/machine_spec.rb +64 -14
  82. data/spec/mods/standard/sets/right/machine_output_spec.rb +2 -17
  83. data/spec/mods/standard/sets/right/script_spec.rb +9 -5
  84. data/spec/mods/standard/sets/right/style_spec.rb +11 -5
  85. data/spec/mods/standard/sets/type/coffeescript_spec.rb +5 -7
  86. data/spec/mods/standard/sets/type/css_spec.rb +3 -4
  87. data/spec/mods/standard/sets/type/javascript_spec.rb +3 -5
  88. data/spec/mods/standard/sets/type/scss_spec.rb +4 -7
  89. data/spec/mods/standard/sets/type/skin_spec.rb +29 -8
  90. metadata +5 -4
  91. data/mods/standard/sets/right/structure.rb +0 -12
@@ -2,7 +2,7 @@ Description:
2
2
  Generates new set files in mods and matching specs.
3
3
 
4
4
  Example:
5
- rails generate set standard type tshirt
5
+ wagn generate set standard type tshirt
6
6
 
7
7
  This will create:
8
8
  mods/standard/sets/type/tshirt.rb
data/lib/card/loader.rb CHANGED
@@ -83,7 +83,7 @@ class Card
83
83
 
84
84
 
85
85
  def load_sets_by_pattern
86
- Card.set_patterns.reverse.map(&:key).each do |set_pattern|
86
+ Card.set_patterns.reverse.map(&:pattern_code).each do |set_pattern|
87
87
  pattern_tmp_dir = "#{Wagn.paths['tmp/sets'].first}/#{set_pattern}"
88
88
  if rewrite_tmp_files?
89
89
  Dir.mkdir pattern_tmp_dir
data/lib/card/set.rb CHANGED
@@ -1,74 +1,148 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
-
4
3
  class Card
5
4
  module Set
6
5
 
7
- mattr_accessor :includable_modules, :base_modules, :traits, :current
8
- @@includable_modules, @@base_modules = {}, []
6
+ mattr_accessor :modules, :traits
7
+ @@modules = { :base=>[], :base_format=>{}, :nonbase=>{}, :nonbase_format=>{} }
9
8
 
9
+ =begin
10
+ A "Set" is a group of cards to which "Rules" may be applied. Sets can be as specific as
11
+ a single card, as general as all cards, or anywhere in between.
10
12
 
11
- # View definitions
12
- #
13
- # When you declare:
14
- # view :view_name, "<set>" do |args|
15
- #
16
- # Methods are defined on the format
17
- #
18
- # The external api with checks:
19
- # render(:viewname, args)
20
- #
21
- # Roughly equivalent to:
22
- # render_viewname(args)
23
- #
24
- # The internal call that skips the checks:
25
- # _render_viewname(args)
26
- #
27
- # Each of the above ultimately calls:
28
- # _final(_set_key)_viewname(args)
13
+ Rules take two main forms: card rules and code rules.
29
14
 
30
- #
31
- # ~~~~~~~~~~ VIEW DEFINITION
32
- #
15
+ "Card rules" are defined in card content. These are generally configured via the web
16
+ interface and are thus documented at http://wagn.org/rules.
33
17
 
34
- def view *args, &block
35
- format do view *args, &block end
18
+ "Code rules" can be defined in a "set file" within any "Mod" (short for both "module" and
19
+ "modification"). In accordance with Wagn's "MoVE" architecture, there are two main kinds of
20
+ code rules you can create in a set file: Views, and Events. Events are associated with the
21
+ Card class, and Views are associated with a Format class. You can also use set files to
22
+ add or override Card and/or Format methods directly. The majority of Wagn code is contained
23
+ in these files.
24
+
25
+ (FIXME - define mod, add generator)
26
+
27
+ Whenever you fetch or instantiate a card, it will automatically include all the
28
+ set modules defined in set files associated with sets of which it is a member. This
29
+ entails both simple model methods and "events", which are special methods explored
30
+ in greater detail below.
31
+
32
+ For example, say you have a Plaintext card named "Philipp+address", and you have set files
33
+ for the following sets:
34
+
35
+ * all cards
36
+ * all Plaintext cards
37
+ * all cards ending in +address
38
+
39
+ When you run this:
40
+
41
+ mycard = Card.fetch 'Philipp+address'
42
+
43
+ ...then mycard will include the set modules associated with each of those sets in the above
44
+ order. (The order is determined by the set pattern; see lib/card/set_pattern.rb for more
45
+ information about set_ptterns and mods/core/sets/all/fetch.rb for more about fetching.)
46
+
47
+ Similarly, whenever a Format object is instantiated for a card, it includes all views
48
+ associated with BOTH (a) sets of which the card is a member and (b) the current format or
49
+ its ancestors. More on defining views below.
50
+
51
+
52
+ In order to have a set file associated with "all cards ending in +address", you could create
53
+ a file in mywagn/mods/mymod/sets/right/address.rb. The recommended mechanism for doing so
54
+ is running `wagn generate set modname set_pattern set_anchor`. In the current example, this
55
+ would translate to `wagn generate set mymod right address`. Note that both the set_pattern
56
+ and the set_anchor must correspond to the codename of a card in the database to function
57
+ correctly.
58
+
59
+
60
+ When Wagn loads, it uses these files to autogenerate a tmp_file that uses this set file to
61
+ createa Card::Set::Right::Address module which itself is extended with Card::Set. A set file
62
+ is "just ruby" but is generally quite concise because Wagn uses its file location to
63
+ autogenerate ruby module names and then uses Card::Set module to provide additional API.
64
+
65
+
66
+ View definitions
67
+
68
+ When you declare:
69
+ view :view_name do |args|
70
+ #...your code here
71
+ end
72
+
73
+ Methods are defined on the format
74
+
75
+ The external api with checks:
76
+ render(:viewname, args)
77
+
78
+
79
+ =end
80
+
81
+ module Format
82
+ mattr_accessor :views
83
+ @@views = {}
84
+
85
+ def view view, *args, &block
86
+ view = view.to_name.key.to_sym
87
+ views[self] ||= {}
88
+ view_block = views[self][view] = if block_given?
89
+ Card::Format.extract_class_vars view, args[0]
90
+ block
91
+ else
92
+ alias_block view, args
93
+ end
94
+ define_method "_view_#{ view }", view_block
95
+ end
96
+
97
+ def alias_block view, args
98
+ opts = Hash===args[0] ? args.shift : { :view => args.shift }
99
+ opts[:mod] ||= self
100
+ opts[:view] ||= view
101
+ views[ opts[:mod] ][ opts[:view] ] or fail
102
+ rescue
103
+ raise "cannot find #{ opts[:view] } view in #{ opts[:mod] }; failed to alias #{view} in #{self}"
104
+ end
105
+
36
106
  end
37
107
 
38
- def format fmt=nil, &block
39
- if block_given?
40
- f = Card::Format
41
- format = fmt.nil? ? f : f.get_format(fmt)
42
- format.class_eval &block
43
- else
44
- fail "block required"
108
+ def format format=nil, &block
109
+ klass = Card::Format.format_class_name format # format class name, eg. HtmlFormat
110
+ mod = const_get_or_set klass do # called on current set module, eg Card::Set::Type::Pointer
111
+ m = Module.new # yielding set format module, eg Card::Set::Type::Pointer::HtmlFormat
112
+ register_set_format Card.const_get(klass), m
113
+ m.extend Card::Set::Format
114
+ m
115
+ end
116
+ mod.class_eval &block
117
+ end
118
+
119
+ def view *args, &block
120
+ format do
121
+ view *args, &block
45
122
  end
46
123
  end
124
+
47
125
 
48
126
  def event event, opts={}, &final
49
127
  opts[:on] = [:create, :update ] if opts[:on] == :save
50
128
 
51
- mod = Card::Set.current[:module]
52
129
  Card.define_callbacks event
53
130
 
54
- mod.class_eval do
131
+ class_eval do
55
132
  final_method = "#{event}_without_callbacks" #should be private?
56
133
  define_method final_method, &final
57
134
 
58
135
  define_method event do
59
- # Rails.logger.info "running #{event} for #{name}"
60
136
  run_callbacks event do
61
- # Rails.logger.info "calling event: #{event} for #{self}"
62
137
  send final_method
63
138
  end
64
139
  end
65
140
  end
66
141
 
67
- set_event_callbacks event, mod, opts
142
+ set_event_callbacks event, opts
68
143
  end
69
144
 
70
145
 
71
-
72
146
  #
73
147
  # ActiveCard support: accessing plus cards as attributes
74
148
  #
@@ -88,64 +162,35 @@ class Card
88
162
  options = args.extract_options!
89
163
  add_traits args, options.merge( :writer=>true )
90
164
  end
91
-
92
-
93
- def const_missing const
94
- if const.to_s =~ /^([A-Z]\S*)ID$/ and code=$1.underscore.to_sym
95
- if card_id = Codename[code]
96
- const_set const, card_id
97
- else
98
- raise "Missing codename #{code} (#{const})"
99
- end
100
- else
101
- super
102
- end
103
- end
104
-
105
- #
106
- # Singleton methods
107
- #
108
165
 
166
+
167
+
168
+
169
+ # the set loading process has two main phases:
170
+
171
+ # 1. Definition: interpret each set file, creating/defining set and set_format modules
172
+ # 2. Organization: have base classes include modules associated with the "all" set, and
173
+ # clean up the other modules
174
+
109
175
  class << self
176
+
177
+ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178
+ # Definition Phase
110
179
 
111
- def extended mod
112
- # document!
180
+ # each set file calls `extend Card::Set` when loaded
181
+ def extended mod
113
182
  register_set mod
114
183
  end
115
-
116
- def method_key opts
117
- Card.set_patterns.each do |pclass|
118
- if !pclass.opt_keys.map(&opts.method(:has_key?)).member? false;
119
- return pclass.method_key_from_opts(opts)
120
- end
121
- end
122
- end
123
-
184
+
124
185
  def register_set set_module
125
- if all_set?( set_module )
126
- self.current = { :module=>Card, :opts=>{} }
127
- base_modules << set_module unless set_module == Card
186
+ if set_module.all_set?
187
+ modules[ :base ] << set_module
128
188
  else
129
- self.current = { :module=>set_module, :opts=>opts_from_module( set_module ) }
189
+ modules[ :nonbase ][ set_module.shortname ] ||= []
190
+ modules[ :nonbase ][ set_module.shortname ] << set_module
130
191
  end
131
-
132
- includable_modules[ set_module.name ] = set_module unless set_module == Card
133
- end
134
-
135
- def all_set? set_module
136
- set_module == Card or set_module.name =~ /^Card::Set::All::/
137
192
  end
138
-
139
- def opts_from_module set_module
140
- if name_parts = set_module.to_s.split('::')[2..-1]
141
- #FIXME - does not handle set patterns with multiple opts (eg type plus right)
142
- pattern, anchor = name_parts.map { |part| part.underscore.to_sym }
143
- { pattern => anchor }
144
- else
145
- { }
146
- end
147
- end
148
-
193
+
149
194
  def write_tmp_file set_pattern, anchor, from_file, seq
150
195
  # FIXME - this does not properly handle anchorless sets
151
196
  # There are special hacks for *all, but others (like *rstar) will not be found by
@@ -166,48 +211,87 @@ EOF
166
211
  File.write to_file, file_content
167
212
  to_file
168
213
  end
214
+
215
+
216
+ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217
+ # Organization Phase
169
218
 
170
-
219
+ # "base modules" are modules that are permanently included on the Card or Format class
220
+ # "nonbase modules" are included dynamically on singleton_classes
171
221
  def process_base_modules
172
- base_modules.each do |mod|
222
+ process_base_module_list modules[:base], Card
223
+ modules[:base_format].each do |format_class, modules_list|
224
+ process_base_module_list modules_list, format_class
225
+ end
226
+ modules.delete :base
227
+ modules.delete :base_format
228
+ end
229
+
230
+ def process_base_module_list list, klass
231
+ list.each do |mod|
173
232
  if mod.instance_methods.any?
174
- Card.send :include, mod
233
+ klass.send :include, mod
175
234
  end
176
235
  if class_methods = mod.const_get_if_defined( :ClassMethods )
177
- Card.send :extend, class_methods
236
+ klass.send :extend, class_methods
178
237
  end
179
- includable_modules.delete mod.name
180
238
  end
181
- @@base_modules = []
182
239
  end
183
240
 
184
241
  def clean_empty_modules
185
- includable_modules.each do |mod_name, mod|
186
- if mod.instance_methods.empty?
187
- includable_modules.delete mod_name
188
- end
242
+ clean_empty_module_from_hash modules[ :nonbase ]
243
+ modules[ :nonbase_format ].values.each do |hash|
244
+ clean_empty_module_from_hash hash
189
245
  end
190
246
  end
191
-
247
+
248
+ def clean_empty_module_from_hash hash
249
+ hash.each do |mod_name, modlist|
250
+ modlist.delete_if { |x| x.instance_methods.empty? }
251
+ hash.delete mod_name if modlist.empty?
252
+ end
253
+ end
254
+
192
255
  end
193
256
 
194
257
 
195
- private
258
+ def register_set_format format_class, mod
259
+ if self.all_set?
260
+ modules[ :base_format ][ format_class ] ||= []
261
+ modules[ :base_format ][ format_class ] << mod
262
+ else
263
+ format_hash = modules[ :nonbase_format ][ format_class ] ||= {}
264
+ format_hash[ shortname ] ||= []
265
+ format_hash[ shortname ] << mod
266
+ end
267
+ end
268
+
269
+ def shortname
270
+ parts = name.split '::'
271
+ first = 2 # shortname eliminates Card::Set
272
+ set_class = Card::SetPattern.find parts[first].underscore
273
+
274
+ last = first + ( set_class.anchorless? ? 0 : 1 )
275
+ #FIXME - handle multi-anchor sets like type_plus_right
276
+ parts[first..last].join '::'
277
+ end
196
278
 
279
+ def all_set?
280
+ name =~ /^Card::Set::All::/
281
+ end
197
282
 
198
- def set_event_callbacks event, mod, opts
283
+ private
284
+
285
+
286
+ def set_event_callbacks event, opts
199
287
  [:before, :after, :around].each do |kind|
200
288
  if object_method = opts.delete(kind)
201
- options = { :prepend => true }
202
- if mod == Card
203
- options[:if] = proc { |c| c.event_applies? opts }
204
- else
205
- parts = mod.name.split '::'
206
- set_class_key, anchor_or_placeholder = parts[-2].underscore.to_sym, parts[-1].underscore
207
- set_key = Card::Set.method_key( set_class_key => anchor_or_placeholder )
208
- options[:if] = proc { |c| c.method_keys.member? set_key and c.event_applies? opts }
209
- end
210
- Card.class_eval { set_callback object_method, kind, event, options }
289
+ this_set_module = self
290
+ Card.class_eval do
291
+ set_callback object_method, kind, event, :prepend=>true, :if=> proc { |c|
292
+ c.singleton_class.include?( this_set_module ) and c.event_applies? opts
293
+ }
294
+ end
211
295
  end
212
296
  end
213
297
  end
@@ -218,7 +302,7 @@ EOF
218
302
  end
219
303
 
220
304
  def add_traits args, options
221
- mod = Card::Set.current[:module]
305
+ mod = self
222
306
  # raise "Can't define card traits on all set" if mod == Card
223
307
  mod_traits = get_traits mod
224
308
 
@@ -1,8 +1,12 @@
1
1
  class Card
2
2
  class SetPattern
3
-
3
+
4
4
  class << self
5
- attr_accessor :key, :key_id, :opt_keys, :junction_only, :method_key, :assigns_type, :anchorless
5
+ attr_accessor :pattern_code, :pattern_id, :junction_only, :assigns_type, :anchorless
6
+
7
+ def find pattern_code
8
+ Card.set_patterns.find { |sub| sub.pattern_code == pattern_code }
9
+ end
6
10
 
7
11
  def junction_only?
8
12
  !!junction_only
@@ -16,37 +20,28 @@ class Card
16
20
  super if pattern_applies? card
17
21
  end
18
22
 
19
- def key_name
20
- Card.fetch(self.key_id, :skip_modules=>true).cardname
23
+ def pattern
24
+ Card.fetch(self.pattern_id, :skip_modules=>true).cardname
21
25
  end
22
26
 
23
- def register key, opts={}
24
- if self.key_id = Card::Codename[key]
25
- self.key = key
27
+ def register pattern_code, opts={}
28
+ if self.pattern_id = Card::Codename[pattern_code]
29
+ self.pattern_code = pattern_code
26
30
  Card.set_patterns.insert opts.delete(:index).to_i, self
27
- if self.anchorless = !respond_to?( :anchor_name )
28
- self.method_key = opts[:method_key] || key
29
- end
30
- self.opt_keys = Array.wrap( opts.delete(:opt_keys) || key.to_sym )
31
+ self.anchorless = !respond_to?( :anchor_name )
31
32
  opts.each { |key, val| send "#{key}=", val }
32
33
  else
33
- warn "no codename for key #{key}"
34
+ warn "no codename for pattern_code #{pattern_code}"
34
35
  end
35
36
  end
36
37
 
37
- def method_key_from_opts opts
38
- method_key || ((opt_keys.map do |opt_key|
39
- opts[opt_key].to_name.key.gsub('+', '-')
40
- end << key) * '_' )
41
- end
42
-
43
38
  def pattern_applies? card
44
39
  junction_only? ? card.cardname.junction? : true
45
40
  end
46
41
 
47
- def write_tmp_file pattern_key, from_file, seq
48
- to_file = "#{Wagn.paths['tmp/set_patterns'].first}/#{seq}-#{pattern_key}.rb"
49
- klass = "Card::SetPattern::#{pattern_key.camelize}Pattern"
42
+ def write_tmp_file pattern_code, from_file, seq
43
+ to_file = "#{Wagn.paths['tmp/set_patterns'].first}/#{seq}-#{pattern_code}.rb"
44
+ klass = "Card::#{pattern_code.camelize}Set"
50
45
  file_content = <<EOF
51
46
  # -*- encoding : utf-8 -*-
52
47
  class #{klass} < Card::SetPattern
@@ -58,7 +53,7 @@ class #{klass} < Card::SetPattern
58
53
 
59
54
  # ~~~~~~~~~~~ below autogenerated; above pulled from #{from_file} ~~~~~~~~~~~
60
55
  end
61
- register "#{pattern_key}", (options || {})
56
+ register "#{pattern_code}", (options || {})
62
57
  end
63
58
 
64
59
  EOF
@@ -71,93 +66,64 @@ EOF
71
66
  # Instance methods
72
67
 
73
68
  def initialize card
74
-
75
69
  unless self.class.anchorless?
76
70
  @anchor_name = self.class.anchor_name(card).to_name
77
-
78
71
  @anchor_id = if self.class.respond_to? :anchor_id
79
72
  self.class.anchor_id card
80
73
  else
81
74
  Card.fetch_id @anchor_name
82
75
  end
83
76
  end
84
-
85
77
  self
86
78
  end
87
79
 
88
-
89
- def set_module_name
90
- tail = case
91
- when self.class.anchorless? ; self.class.key.camelize
92
- when opt_vals.member?( nil ) ; nil
93
- else "#{self.class.key.camelize}::#{opt_vals.map(&:to_s).map(&:camelize) * '::'}"
80
+ def module_key
81
+ (defined? @module_key) ? @module_key : @module_key = begin
82
+ if self.class.anchorless?
83
+ self.class.pattern_code.camelize
84
+ elsif anchor_codenames
85
+ "#{self.class.pattern_code.camelize}::#{anchor_codenames.map(&:to_s).map(&:camelize) * '::'}"
94
86
  end
95
- tail && "Card::Set::#{ tail }"
96
- end
97
-
98
- def set_const
99
- if set_module = self.set_module_name
100
- Card::Set.includable_modules[ set_module ]
101
87
  end
102
-
103
- rescue Exception => e
104
- warn "exception set_const #{e.inspect}, #{e.backtrace*"\n"}"
105
88
  end
106
89
 
107
- def get_method_key
108
- if self.class.anchorless?
109
- self.class.method_key
110
- else
111
- opts = {}
112
- self.class.opt_keys.each_with_index do |key, index|
113
- return nil unless opt_vals[index]
114
- opts[key] = opt_vals[index]
115
- end
116
- self.class.method_key_from_opts opts
117
- end
90
+ def module_list
91
+ module_key and Card::Set.modules[ :nonbase ][ module_key ]
118
92
  end
119
93
 
120
- def opt_vals
121
- if @opt_vals.nil?
122
- @opt_vals = self.class.anchorless? ? [] : find_opt_vals
123
- end
124
- @opt_vals
94
+ def format_module_list klass
95
+ module_key and hash = Card::Set.modules[ :nonbase_format ][ klass ] and hash[ module_key ]
125
96
  end
126
97
 
127
- def find_opt_vals
128
- anchor_parts = if self.class.opt_keys.size > 1
129
- [ @anchor_name.left, @anchor_name.right ]
130
- else
131
- [ @anchor_name ]
132
- end
133
- anchor_parts.map do |part|
98
+ def anchor_codenames
99
+ @anchor_name.parts.map do |part|
134
100
  part_id = Card.fetch_id part
135
- part_id && Card::Codename[ part_id.to_i ] or return []
101
+ part_id && Card::Codename[ part_id.to_i ] or return nil
136
102
  end
137
103
  end
138
104
 
139
- def key_name
140
- @key_name ||= self.class.key_name
105
+ def pattern
106
+ @pattern ||= self.class.pattern
141
107
  end
142
108
 
143
109
  def to_s
144
- self.class.anchorless? ? key_name.s : "#{@anchor_name}+#{key_name}"
110
+ self.class.anchorless? ? pattern.s : "#{@anchor_name}+#{pattern}"
145
111
  end
146
112
 
147
113
  def inspect
148
114
  "<#{self.class} #{to_s.to_name.inspect}>"
149
115
  end
150
116
 
151
- def safe_key()
152
- caps_part = self.class.key.gsub(' ','_').upcase
117
+ def safe_key
118
+ caps_part = self.class.pattern_code.gsub(' ','_').upcase
153
119
  self.class.anchorless? ? caps_part : "#{caps_part}-#{@anchor_name.safe_key}"
154
120
  end
155
121
 
156
122
  def rule_set_key
157
123
  if self.class.anchorless?
158
- self.class.key
124
+ self.class.pattern_code
159
125
  elsif @anchor_id
160
- [ @anchor_id, self.class.key ].map( &:to_s ) * '+'
126
+ [ @anchor_id, self.class.pattern_code ].map( &:to_s ) * '+'
161
127
  end
162
128
  end
163
129