Module: Granite::Action::Preconditions::ClassMethods

Defined in:
lib/granite/action/preconditions.rb

Instance Method Summary collapse

Instance Method Details

#precondition(*args, &block) ⇒ Object

Define preconditions for current action.

Parameters:

  • options (Hash)

    hash with

  • block (Block)

    which returns truthy value when precondition should pass.

  • message (Hash)

    a customizable set of options

  • group (Hash)

    a customizable set of options



47
48
49
50
51
52
53
54
55
56
# File 'lib/granite/action/preconditions.rb', line 47

def precondition(*args, &block)
  options = args.extract_options!
  if block
    add_precondition(BasePrecondition, options, &block)
  elsif args.first.is_a?(Class)
    add_precondition(ObjectPrecondition, *args, options)
  else
    add_preconditions_hash(*args, **options)
  end
end