Module: Antrapol::ToolRack::BlockParamsUtils

Includes:
ConditionUtils
Defined in:
lib/toolrack/block_params_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



38
39
40
41
42
# File 'lib/toolrack/block_params_utils.rb', line 38

def self.included(klass)
  klass.class_eval <<-END
    extend Antrapol::ToolRack::BlockParamsUtils
  END
end

Instance Method Details

#value_from_block(blockKey, defValue, opts = { }, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/toolrack/block_params_utils.rb', line 9

def value_from_block(blockKey, defValue, opts = { }, &block)
  if block
    blockParams = nil
    if not_empty?(opts)
      blockParams = opts[:blockArgs]
    end

    value = nil
    if blockParams.nil?
      value = block.call(blockKey)
    else
      if blockParams.is_a?(Array)
        value = block.call(blockKey, *blockParams)
      else
        value = block.call(blockKey, blockParams)
      end
    end

    block.call(:inspect_given_value, blockKey, opts, value)

    value = defValue if is_empty?(value)

    value
  else
    defValue
  end
end