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) ⇒ Hatchery

Returns a new instance of Hatchery.



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

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

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



7
8
9
# File 'lib/surrogate/hatchery.rb', line 7

def klass
  @klass
end

Instance Method Details

#api_method_for(name) ⇒ Object



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

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

#api_method_namesObject



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

def api_method_names
  api_methods.keys - [:initialize]
end

#api_methodsObject



22
23
24
# File 'lib/surrogate/hatchery.rb', line 22

def api_methods
  @api_methods ||= {}
end

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



14
15
16
17
18
19
20
# File 'lib/surrogate/hatchery.rb', line 14

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