Class: VagrantPlugins::ProxyConf::Action::OnlyOnce
- Inherits:
-
Object
- Object
- VagrantPlugins::ProxyConf::Action::OnlyOnce
- Defined in:
- lib/vagrant-proxyconf/action/only_once.rb
Overview
A middleware class that builds and runs the stack based on the specified block, but only once.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env, opts = {}, &block) ⇒ OnlyOnce
constructor
A new instance of OnlyOnce.
- #recover(env) ⇒ Object
Constructor Details
#initialize(app, env, opts = {}, &block) ⇒ OnlyOnce
Returns a new instance of OnlyOnce.
12 13 14 15 16 17 18 |
# File 'lib/vagrant-proxyconf/action/only_once.rb', line 12 def initialize(app, env, opts = {}, &block) raise ArgumentError, "A block must be given to OnlyOnce" if !block @app = app @before = opts[:before] @block = block end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vagrant-proxyconf/action/only_once.rb', line 20 def call(env) @app.call(env) if !@before if env[@block] logger.debug "Skipping repeated '#{@block}' stack" else logger.debug "'#{@block}' stack invoked first time" env[@block] = true new_env = build_and_run_block(env) env.merge!(new_env) end @app.call(env) if @before end |
#recover(env) ⇒ Object
36 37 38 39 |
# File 'lib/vagrant-proxyconf/action/only_once.rb', line 36 def recover(env) # Call back into our compiled application and recover it. @child_app.recover(env) if @child_app end |