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.



144
145
146
# File 'lib/hatch.rb', line 144

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

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



142
143
144
# File 'lib/hatch.rb', line 142

def error
  @error
end

Class Method Details

.not_empty(error) ⇒ Object



156
157
158
# File 'lib/hatch.rb', line 156

def self.not_empty(error)
  new(error || 'must not be empty') {|value| !value.nil? && !value.empty?}
end

.not_nil(error) ⇒ Object



148
149
150
# File 'lib/hatch.rb', line 148

def self.not_nil(error)
  new(error || 'must not be nil') {|value| !value.nil?}
end

.positive_number(error) ⇒ Object



152
153
154
# File 'lib/hatch.rb', line 152

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