Class: Builderator::Config::Attributes::Collection
- Inherits:
-
Builderator::Config::Attributes
- Object
- Builderator::Config::Attributes
- Builderator::Config::Attributes::Collection
- Defined in:
- lib/builderator/config/attributes.rb
Overview
Enumerable wrapper for collections
Class Attribute Summary collapse
-
.name ⇒ Object
Returns the value of attribute name.
-
.namespace_class ⇒ Object
Returns the value of attribute namespace_class.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Allow a single instance to be selected.
Attributes inherited from Builderator::Config::Attributes
#attributes, #extends, #nodes, #parent
Class Method Summary collapse
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Enumerable methods return namespace instances.
-
#fetch(instance_name, **options, &block) ⇒ Object
(also: #[])
Get namespace instances.
- #name ⇒ Object
- #use(instance_name) ⇒ Object
Methods inherited from Builderator::Config::Attributes
#==, attribute, #clean, collection, #compile, #dirty, #dirty!, #initialize, #merge, namespace, #reset!, #root, #root?, #seal, #to_json, #unseal
Constructor Details
This class inherits a constructor from Builderator::Config::Attributes
Class Attribute Details
.name ⇒ Object
Returns the value of attribute name.
313 314 315 |
# File 'lib/builderator/config/attributes.rb', line 313 def name @name end |
.namespace_class ⇒ Object
Returns the value of attribute namespace_class.
314 315 316 |
# File 'lib/builderator/config/attributes.rb', line 314 def namespace_class @namespace_class end |
Instance Attribute Details
#current ⇒ Object (readonly)
Allow a single instance to be selected
326 327 328 |
# File 'lib/builderator/config/attributes.rb', line 326 def current @current end |
Class Method Details
.create(collection_name, &definition) ⇒ Object
316 317 318 319 320 321 322 |
# File 'lib/builderator/config/attributes.rb', line 316 def create(collection_name, &definition) collection = Class.new(self) collection.name = collection_name collection.namespace_class = Namespace.create(collection_name, &definition) collection end |
Instance Method Details
#each(&block) ⇒ Object
Enumerable methods return namespace instances
332 333 334 335 336 |
# File 'lib/builderator/config/attributes.rb', line 332 def each(&block) attributes.each_key do |instance_name| block.call(instance_name, fetch(instance_name)) end end |
#fetch(instance_name, **options, &block) ⇒ Object Also known as: []
Get namespace instances
343 344 345 346 347 348 349 350 |
# File 'lib/builderator/config/attributes.rb', line 343 def fetch(instance_name, **, &block) nodes[instance_name] ||= self.class.namespace_class.new( attributes[instance_name], :collection => self, :name => instance_name, :parent => self, :extends => [:extends], &block) end |
#name ⇒ Object
338 339 340 |
# File 'lib/builderator/config/attributes.rb', line 338 def name self.class.name end |
#use(instance_name) ⇒ Object
327 328 329 |
# File 'lib/builderator/config/attributes.rb', line 327 def use(instance_name) @current = fetch(instance_name) end |