Class: Surrogate::Hatchling

Inherits:
Object
  • Object
show all
Defined in:
lib/surrogate/hatchling.rb

Overview

This contains the unique behaviour for each instance It handles method invocation and records the appropriate information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, hatchery) ⇒ Hatchling

Returns a new instance of Hatchling.



11
12
13
# File 'lib/surrogate/hatchling.rb', line 11

def initialize(instance, hatchery)
  self.instance, self.hatchery = instance, hatchery
end

Instance Attribute Details

#hatcheryObject

Returns the value of attribute hatchery.



9
10
11
# File 'lib/surrogate/hatchling.rb', line 9

def hatchery
  @hatchery
end

#instanceObject

Returns the value of attribute instance.



9
10
11
# File 'lib/surrogate/hatchling.rb', line 9

def instance
  @instance
end

Instance Method Details

#api_methodsObject



15
16
17
# File 'lib/surrogate/hatchling.rb', line 15

def api_methods
  hatchery.api_methods
end

#invocations(method_name) ⇒ Object



34
35
36
# File 'lib/surrogate/hatchling.rb', line 34

def invocations(method_name)
  invoked_methods[method_name]
end

#invoke_method(method_name, args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/surrogate/hatchling.rb', line 19

def invoke_method(method_name, args, &block)
  invocation = Invocation.new(args, &block)
  invoked_methods[method_name] << invocation
  if setter?(method_name) || !has_ivar?(method_name)
    return get_default method_name, invocation, &block
  end
  interfaces_must_match! method_name, args
  Value.factory(get_ivar method_name).value(method_name)
end

#prepare_method(method_name, args, &block) ⇒ Object



29
30
31
32
# File 'lib/surrogate/hatchling.rb', line 29

def prepare_method(method_name, args, &block)
  must_know method_name
  set_ivar method_name, Value.factory(*args, &block)
end