Class: Surrogate::Hatchery
- Inherits:
-
Object
- Object
- Surrogate::Hatchery
- 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
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
- #api_method_for(name) ⇒ Object
- #api_method_names ⇒ Object
- #api_methods ⇒ Object
- #define(method_name, options = {}, &block) ⇒ Object
-
#initialize(klass) ⇒ Hatchery
constructor
A new instance of Hatchery.
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
#klass ⇒ Object
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) = api_methods[name] && .default_proc end |
#api_method_names ⇒ Object
26 27 28 |
# File 'lib/surrogate/hatchery.rb', line 26 def api_method_names api_methods.keys - [:initialize] end |
#api_methods ⇒ Object
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, ={}, &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, , block klass end |