Class: Cobble::Binding

Inherits:
Object
  • Object
show all
Defined in:
lib/cobble/binding.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Binding

:nodoc:



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cobble/binding.rb', line 7

def initialize(name, options = {}) # :nodoc:
  self.name = name
  self.type = :build
  self.options = {}
  parse_options(options)

  self.attributes_for(name)

  attr_for = self.options.delete(:attributes_for)
  if attr_for
    self.attributes_for(attr_for)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/cobble/binding.rb', line 36

def method_missing(sym, *args, &block)
  unless self.options[sym]
    if block_given?
      self.options[sym] = yield
    end
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/cobble/binding.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/cobble/binding.rb', line 5

def options
  @options
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/cobble/binding.rb', line 4

def type
  @type
end

Instance Method Details

#attributes_for(names) ⇒ Object



30
31
32
33
34
# File 'lib/cobble/binding.rb', line 30

def attributes_for(names)
  [names].flatten.each do |name|
    self.options = Cobble.attribs(name).dup.merge(self.options)
  end
end

#execute(&block) ⇒ Object



25
26
27
28
# File 'lib/cobble/binding.rb', line 25

def execute(&block)
  eval_options
  instance_eval(&block)
end

#fake(name, *args) ⇒ Object



21
22
23
# File 'lib/cobble/binding.rb', line 21

def fake(name, *args)
  Cobble::Fakes.execute(name.to_sym, *args)
end