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.
8 9 10 |
# File 'lib/diecut/configurable.rb', line 8 def target_name @target_name end |
Instance Method Details
#absorb_context(from) ⇒ Object
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 73 74 |
# File 'lib/diecut/configurable.rb', line 38 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 FieldClash, "#{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 FieldClash, "#{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
87 88 89 90 91 92 93 94 95 |
# File 'lib/diecut/configurable.rb', line 87 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
10 11 12 |
# File 'lib/diecut/configurable.rb', line 10 def build_subclass(name) Class.new(self).tap{|cc| cc.target_name = name } end |
#classname ⇒ Object
14 15 16 |
# File 'lib/diecut/configurable.rb', line 14 def classname name || superclass.name end |
#deep_field_names ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/diecut/configurable.rb', line 18 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
34 35 36 |
# File 'lib/diecut/configurable.rb', line 34 def inspect return "#<#{classname}:#{target_name}:(#{deep_field_names.join(",")})>" end |
#walk_path(field_path) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/diecut/configurable.rb', line 76 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 |