Module: Canned::Context::Matchers::Load

Included in:
Actor, Default
Defined in:
lib/canned/context/matchers/load.rb

Instance Method Summary collapse

Instance Method Details

#loaded(_name, _options = {}, &_block) ⇒ Object Also known as: loads

Loads a resource and returns a resource context.

of that returned by this function.

Parameters:

  • _name (String|Symbol)

    Resource name

  • _options (Hash) (defaults to: {})

    Various options:

    • as: If given, the resource will use as as alias for where blocks instead of the name.

  • _block (Block)

    If given, then the block will be evaluated in the resource context and the result



14
15
16
17
18
19
20
# File 'lib/canned/context/matchers/load.rb', line 14

def loaded(_name, _options={}, &_block)
  _chain_context(Canned::Context::Resource, _block) do |stack|
    res = @ctx.resources[_name]
    next false if res.nil?
    stack.push(:resource, _options.fetch(:as, _name), res)
  end
end