Module: Canned::Context::Matchers::AsksWith

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

Instance Method Summary collapse

Instance Method Details

#asked_with(_key, _options = {}, &_block) ⇒ Object Also known as: asks_with

Loads a value context for a given parameter

of that returned by this function.

Parameters:

  • Parameter (String|Symbol)

    key

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

    Various options:

    • as: If given, the value will use this value as alias for where blocks instead of the key.

  • _block (Block)

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



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

def asked_with(_key, _options={}, &_block)
  _chain_context(Canned::Context::Value, _block) do |stack|
    param = @ctx.params[_key]
    next false if param.nil?
    stack.push :value, _options.fetch(:as, _key), param
  end
end

#asked_with_id(_key, _options = {}, &_block) ⇒ Object Also known as: asks_with_id

Same as asked_with but transforms parameter to an int.



24
25
26
27
28
29
30
# File 'lib/canned/context/matchers/asks_with.rb', line 24

def asked_with_id(_key, _options={}, &_block)
  _chain_context(Canned::Context::Value, _block) do |stack|
    param = @ctx.params[_key]
    next false if param.nil?
    stack.push :value, _options.fetch(:as, _key), param.to_i
  end
end