Class: BlueprintsBoy::Dependency

Inherits:
BasicObject
Defined in:
lib/blueprints_boy/dependency.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, *args) ⇒ Dependency

Returns a new instance of Dependency.



2
3
4
5
6
7
# File 'lib/blueprints_boy/dependency.rb', line 2

def initialize(name, *args)
  @name = name
  @options = args.extract_options!
  @blueprint_name = args.first || @name
  @registry = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



19
20
21
22
# File 'lib/blueprints_boy/dependency.rb', line 19

def method_missing(method, *args, &block)
  @registry << [method, args, block]
  self
end

Instance Method Details

#to_procObject



9
10
11
12
13
14
15
16
17
# File 'lib/blueprints_boy/dependency.rb', line 9

def to_proc
  name, options, registry, blueprint_name = @name, @options, @registry, @blueprint_name
  ::Proc.new do
    build blueprint_name => options
    registry.inject(blueprint_data(name)) do |value, (method, args, block)|
      value.send(method, *args, &block)
    end
  end
end