Class: Gexp::Handler::Check::Item

Inherits:
Gexp::Handler::Check show all
Defined in:
lib/gexp/handler/check/item.rb

Instance Attribute Summary

Attributes inherited from Gexp::Handler

#object, #objects, #params, #user

Instance Method Summary collapse

Methods inherited from Gexp::Handler

#initialize

Constructor Details

This class inherits a constructor from Gexp::Handler

Instance Method Details

#process(params, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gexp/handler/check/item.rb', line 6

def process(params, &block)

  results = params.map do |key, value|
    [
      key,
      value,
      @user.have_with_type?(key.to_s, value),
    ]
  end

  haves = results.map(&:last).all?

  if block_given?
    return block.call(results) if haves
  else
    unless haves
      view = results.map { |r| "#{r.first}_#{r.second}" }
      raise Exception.new("not_have_items-#{view.join(',')}") 
    end

    haves
  end

end