Class: Builderator::Config::Attributes::Collection

Inherits:
Builderator::Config::Attributes show all
Defined in:
lib/builderator/config/attributes.rb

Overview

Enumerable wrapper for collections

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Builderator::Config::Attributes

#attributes, #extends, #nodes, #parent

Class Method Summary collapse

Instance Method Summary collapse

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

.nameObject

Returns the value of attribute name.



310
311
312
# File 'lib/builderator/config/attributes.rb', line 310

def name
  @name
end

.namespace_classObject

Returns the value of attribute namespace_class.



311
312
313
# File 'lib/builderator/config/attributes.rb', line 311

def namespace_class
  @namespace_class
end

Instance Attribute Details

#currentObject (readonly)

Allow a single instance to be selected



323
324
325
# File 'lib/builderator/config/attributes.rb', line 323

def current
  @current
end

Class Method Details

.create(collection_name, &definition) ⇒ Object



313
314
315
316
317
318
319
# File 'lib/builderator/config/attributes.rb', line 313

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



329
330
331
332
333
# File 'lib/builderator/config/attributes.rb', line 329

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



340
341
342
343
344
345
346
347
# File 'lib/builderator/config/attributes.rb', line 340

def fetch(instance_name, **options, &block)
  nodes[instance_name] ||= self.class.namespace_class.new(
    attributes[instance_name],
    :collection => self,
    :name => instance_name,
    :parent => self,
    :extends => options[:extends], &block)
end

#nameObject



335
336
337
# File 'lib/builderator/config/attributes.rb', line 335

def name
  self.class.name
end

#use(instance_name) ⇒ Object



324
325
326
# File 'lib/builderator/config/attributes.rb', line 324

def use(instance_name)
  @current = fetch(instance_name)
end