Class: Veto::ValidatesBlock::CheckBlock

Inherits:
ConditionalBlock show all
Defined in:
lib/veto/blocks/validates_block.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ConditionalBlock

#call, #options

Methods inherited from Block

#<<, #call, #children

Constructor Details

#initialize(type, attribute_name, value_or_options = nil) ⇒ CheckBlock

Returns a new instance of CheckBlock.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/veto/blocks/validates_block.rb', line 10

def initialize(type, attribute_name, value_or_options=nil)
  @type = type
  @attribute_name = attribute_name
  options =         
    case value_or_options
    when TrueClass
      {}
    when Hash
      value_or_options
    when Range, Array
      {:in => value_or_options}
    else
      {:with => value_or_options}
    end
  super(options)
end

Class Method Details

.build(*args) ⇒ Object



4
5
6
7
8
# File 'lib/veto/blocks/validates_block.rb', line 4

def self.build(*args)
  block = new(*args)
  block << ::Veto::CheckFactory.new(block.type, block.attribute_name, block.options)
  block
end

Instance Method Details

#attribute_nameObject



27
28
29
# File 'lib/veto/blocks/validates_block.rb', line 27

def attribute_name
  @attribute_name
end

#typeObject



31
32
33
# File 'lib/veto/blocks/validates_block.rb', line 31

def type
  @type
end