Class: EcomDev::ChefSpec::Helpers::RunnerProxy
- Inherits:
-
Object
- Object
- EcomDev::ChefSpec::Helpers::RunnerProxy
show all
- Defined in:
- lib/ecomdev/chefspec/helpers/runner_proxy.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args, &before_initialize) ⇒ RunnerProxy
Returns a new instance of RunnerProxy.
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 5
def initialize(*args, &before_initialize)
@args = args
@constructor_block = before_initialize
@target = nil
@blocks = {
:before => {},
:block => {},
:after => {}
}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
85
86
87
88
89
90
91
92
93
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 85
def method_missing(name, *args, &block)
invoke_blocks(name, :before, *args)
result = target.send(name, *args) do |*block_args|
invoke_blocks(name, :block, *block_args, &block)
end
args.unshift(result)
invoke_blocks(name, :after, *args)
result
end
|
Class Method Details
.instance(*args, &block) ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 108
def instance(*args, &block)
proxy = self.new(*args, &block)
proxy_calls.each do |call|
proxy.send(call[:method], *call[:args], &call[:block])
end
reset
proxy
end
|
.method_missing(method, *args, &block) ⇒ Object
122
123
124
125
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 122
def method_missing(method, *args, &block)
proxy_calls.push({method: method, args: args, block: block})
self
end
|
.reset ⇒ Object
117
118
119
120
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 117
def reset
proxy_calls([])
self
end
|
Instance Method Details
#after(method, instance_eval = false, &block) ⇒ Object
33
34
35
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 33
def after(method, instance_eval = false, &block)
define_proxy_block(method, :after, instance_eval, &block)
end
|
#before(method, instance_eval = false, &block) ⇒ Object
29
30
31
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 29
def before(method, instance_eval = false, &block)
define_proxy_block(method, :before, instance_eval, &block)
end
|
#block(method, instance_eval = false, &block) ⇒ Object
37
38
39
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 37
def block(method, instance_eval = false, &block)
define_proxy_block(method, :block, instance_eval, &block)
end
|
#options(options = {}, override = false) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 16
def options(options = {}, override = false)
if @args.length == 0
@args << options
return @args[0]
end
if override
@args[0] = options
else
@args[0] = options.merge(@args[0])
end
@args[0]
end
|
#proxy_blocks ⇒ Object
41
42
43
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 41
def proxy_blocks
@blocks
end
|
#runner ⇒ Object
45
46
47
|
# File 'lib/ecomdev/chefspec/helpers/runner_proxy.rb', line 45
def runner
target
end
|