Module: Base4R::ChildAttributeMethods
- Included in:
- Attribute
- Defined in:
- lib/attribute.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#add_child(*args) ⇒ Object
add a child.
-
#add_child_attribute(attribute) ⇒ Object
Add a custom prebuilt child
attribute
- an item of classAttribute
shipping_attribute.add_custom_child(BareAttribute.new(:region, ‘WA’)). -
#child(child_name) ⇒ Object
get a specific child.
-
#children ⇒ Object
All the children Attribute objects.
-
#children_map ⇒ Object
a map of all the children names to Attribute class values.
-
#children_names ⇒ Object
All the names of the children.
Class Method Details
.included(base) ⇒ Object
64 65 66 |
# File 'lib/attribute.rb', line 64 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#add_child(*args) ⇒ Object
add a child. The accepted arguments are the same as initializing a new Attribute
shipping_attribute.add_child(:region, 'WA')
shipping_attribute.add_child(:region, :value => 'WA', :namespace => :g)
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/attribute.rb', line 102 def add_child(*args) #parse out the options specified here into keys = (args, :skip_defaults => true) child_name = [:name].to_sym # merge the default options with the extra options with the namespace, name, type options = (self.class.[child_name]||{}).merge() klass = .delete(:klass)||BareAttribute children_map[child_name] = klass.new() end |
#add_child_attribute(attribute) ⇒ Object
Add a custom prebuilt child attribute
- an item of class Attribute
shipping_attribute.add_custom_child(BareAttribute.new(:region, 'WA'))
95 96 97 |
# File 'lib/attribute.rb', line 95 def add_child_attribute(attribute) children_map[attribute.name.to_sym] = attribute end |
#child(child_name) ⇒ Object
get a specific child
116 |
# File 'lib/attribute.rb', line 116 def child(child_name); children_map[child_name.to_sym]; end |
#children ⇒ Object
All the children Attribute objects
121 |
# File 'lib/attribute.rb', line 121 def children; children_map.values; end |
#children_map ⇒ Object
a map of all the children names to Attribute class values
119 |
# File 'lib/attribute.rb', line 119 def children_map; @children_map||={}; end |
#children_names ⇒ Object
All the names of the children
123 |
# File 'lib/attribute.rb', line 123 def children_names; children_map.keys; end |