Class: Surrogate::Hatchery

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

Overview

This manages the definitions that were given to the class The hatchlings are added to the instances, and they look here to find out about how their methods are implemented.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, options) ⇒ Hatchery

Returns a new instance of Hatchery.



13
14
15
16
# File 'lib/surrogate/hatchery.rb', line 13

def initialize(klass, options)
  self.klass, self.options = klass, options
  klass_can_define_api_methods
end

Instance Attribute Details

#klassObject

currently options don’t do anything, they’re just there because the hatchery is the definition of the surrogate so it makes sense for it to store values used by the endower when constructing clones



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

def klass
  @klass
end

#optionsObject

currently options don’t do anything, they’re just there because the hatchery is the definition of the surrogate so it makes sense for it to store values used by the endower when constructing clones



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

def options
  @options
end

Instance Method Details

#api_method_for(name) ⇒ Object



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

def api_method_for(name)
  options = api_methods[name]
  options && options.default_proc
end

#api_method_namesObject



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

def api_method_names
  api_methods.keys - [:initialize]
end

#api_methodsObject



26
27
28
# File 'lib/surrogate/hatchery.rb', line 26

def api_methods
  @api_methods ||= {}
end

#define(method_name, options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/surrogate/hatchery.rb', line 18

def define(method_name, options={}, &block)
  add_api_method_for method_name
  add_verb_helpers_for method_name
  add_noun_helpers_for method_name
  api_methods[method_name] = MethodDefinition.new method_name, options, block
  klass
end