Module: Diecut::Configurable::ClassMethods
- Included in:
- Diecut::Configurable
- Defined in:
- lib/diecut/configurable.rb
Instance Attribute Summary collapse
-
#target_name ⇒ Object
Returns the value of attribute target_name.
Instance Method Summary collapse
- #absorb_context(from) ⇒ Object
- #build_setting(field, is_section = false) ⇒ Object
- #build_subclass(name) ⇒ Object
- #classname ⇒ Object
- #deep_field_names ⇒ Object
- #inspect ⇒ Object
- #walk_path(field_path) ⇒ Object
Instance Attribute Details
#target_name ⇒ Object
Returns the value of attribute target_name.
6 7 8 |
# File 'lib/diecut/configurable.rb', line 6 def target_name @target_name end |
Instance Method Details
#absorb_context(from) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/diecut/configurable.rb', line 36 def absorb_context(from) from.field_names.each do |name| = from.(name) from_value = .default_value = (name) if .nil? if from_value.is_a?(Class) and from_value < Calibrate::Configurable nested = build_subclass("#{target_name}.#{name}") setting(name, nested) nested.absorb_context(from_value) else if .is?(:required) setting(name) else setting(name, from_value) end end next end into_value = .default_value if into_value.is_a?(Class) and into_value < Calibrate::Configurable if from_value.is_a?(Class) and from_value < Calibrate::Configurable into_value.absorb_context(from_value) else raise "Field clash: #{name.inspect} is already a complex value, but a simple value in the absorbed configurable" end else unless from_value.is_a?(Class) and from_value < Calibrate::Configurable # Noop - maybe should compare the default values? - should always # be nil right now... else raise "Field clash: #{name.inspect} is already a simple value, but a complex value on the absorbed configurable" end end end end |
#build_setting(field, is_section = false) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/diecut/configurable.rb', line 85 def build_setting(field, is_section = false) nested = walk_path(field).last.klass if is_section nested.setting(field.last, build_subclass("#{target_name}.#{field.last}")) else nested.setting(field.last) end end |
#build_subclass(name) ⇒ Object
8 9 10 |
# File 'lib/diecut/configurable.rb', line 8 def build_subclass(name) Class.new(self).tap{|cc| cc.target_name = name } end |
#classname ⇒ Object
12 13 14 |
# File 'lib/diecut/configurable.rb', line 12 def classname name || superclass.name end |
#deep_field_names ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/diecut/configurable.rb', line 16 def deep_field_names field_names.map do |name| field_value = (name).default_value if field_value==self return ["LOOPED"] end if field_value.is_a?(Class) and field_value < Diecut::Configurable field_value.deep_field_names.map do |subname| "#{name}.#{subname}" end else name end end.flatten end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/diecut/configurable.rb', line 32 def inspect return "#<#{classname}:#{target_name}:(#{deep_field_names.join(",")})>" end |
#walk_path(field_path) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/diecut/configurable.rb', line 74 def walk_path(field_path) first, *rest = *field_path segment = PathSegment.new(self, first.to_sym) if rest.empty? [segment] else [segment] + segment.nested.walk_path(rest) end end |