Class: Hatch::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/hatch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, &block) ⇒ Validation

Returns a new instance of Validation.



124
125
126
# File 'lib/hatch.rb', line 124

def initialize(error, &block)
  @error, @block = error, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



122
123
124
# File 'lib/hatch.rb', line 122

def block
  @block
end

#errorObject (readonly)

Returns the value of attribute error.



122
123
124
# File 'lib/hatch.rb', line 122

def error
  @error
end

Class Method Details

.positive_number(error) ⇒ Object



132
133
134
# File 'lib/hatch.rb', line 132

def self.positive_number(error)
  new(error || "must be a positive number") {|value| !value.nil? && value > 0}
end

.presence(error) ⇒ Object



128
129
130
# File 'lib/hatch.rb', line 128

def self.presence(error)
  new(error || "must be present") {|value| !value.nil? && !value.empty?}
end