Class: KathyLee::Attributes::Binding

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, &block) ⇒ Binding

Returns a new instance of Binding.



7
8
9
10
11
# File 'lib/kathy_lee/attributes/binding.rb', line 7

def initialize(attributes = {}, &block)
  self.results = {}
  self.attributes = attributes
  self.code_block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, args = nil, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/kathy_lee/attributes/binding.rb', line 24

def method_missing(sym, args = nil, &block)
  self.results[sym] = args unless args.nil?
  if block_given?
    self.results[sym] = block.call
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#code_blockObject

Returns the value of attribute code_block.



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

def code_block
  @code_block
end

#resultsObject

Returns the value of attribute results.



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

def results
  @results
end

Instance Method Details

#fake(name) ⇒ Object



20
21
22
# File 'lib/kathy_lee/attributes/binding.rb', line 20

def fake(name)
  KathyLee::Fakes.execute(name)
end

#process!Object



13
14
15
16
17
18
# File 'lib/kathy_lee/attributes/binding.rb', line 13

def process!
  if self.code_block
    instance_eval(&self.code_block)
  end
  self.results.merge!(self.attributes)
end