Class: Blueprints::Dependency
- Inherits:
-
Object
- Object
- Blueprints::Dependency
- Defined in:
- lib/blueprints/dependency.rb
Overview
Class for defining blueprint dependencies.
Instance Method Summary collapse
-
#initialize(name, *args) ⇒ Dependency
constructor
Initializes new Blueprints::Dependency object.
-
#method_missing(method, *args, &block) ⇒ Blueprints::Dependency
Catches all missing methods to later replay when asking for value.
-
#to_proc ⇒ Proc
Returns block that builds blueprint (if necessary) takes instance variable for this dependency and calls all methods from method registry.
Constructor Details
#d(name, options = {}) ⇒ Dependency #d(name, instance_variable_name, options = {}) ⇒ Dependency
Initializes new Blueprints::Dependency object.
23 24 25 26 27 28 |
# File 'lib/blueprints/dependency.rb', line 23 def initialize(name, *args) @name = name @options = args. @iv_name = (args.first || @name).to_s.gsub('.', '_') @registry = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Blueprints::Dependency
Catches all missing methods to later replay when asking for value.
44 45 46 47 |
# File 'lib/blueprints/dependency.rb', line 44 def method_missing(method, *args, &block) @registry << [method, args, block] self end |
Instance Method Details
#to_proc ⇒ Proc
Returns block that builds blueprint (if necessary) takes instance variable for this dependency and calls all methods from method registry.
32 33 34 35 36 37 38 39 40 |
# File 'lib/blueprints/dependency.rb', line 32 def to_proc name, , registry, variable_name = @name, @options, @registry, @iv_name Proc.new do build name => registry.inject(instance_variable_get(:"@#{variable_name}")) do |value, (method, args, block)| value.send(method, *args, &block) end end end |