Class: PluckMap::AttributeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pluck_map/attribute_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAttributeBuilder

Returns a new instance of AttributeBuilder.



16
17
18
# File 'lib/pluck_map/attribute_builder.rb', line 16

def initialize
  @attributes = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(attribute_name, *args) ⇒ Object



20
21
22
23
24
25
# File 'lib/pluck_map/attribute_builder.rb', line 20

def method_missing(attribute_name, *args)
  options = args.extract_options!
  options[:value] = args.first unless args.empty?
  @attributes.push PluckMap::Attribute.new(attribute_name, options)
  :attribute_added
end

Class Method Details

.build(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/pluck_map/attribute_builder.rb', line 6

def self.build(&block)
  builder = self.new
  if block.arity == 1
    block.call(builder)
  else
    builder.instance_eval(&block)
  end
  builder.instance_variable_get(:@attributes).freeze
end