Class: Hatch::Validation
- Inherits:
-
Object
- Object
- Hatch::Validation
- Defined in:
- lib/hatch.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(error, &block) ⇒ Validation
constructor
A new instance of Validation.
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
122 123 124 |
# File 'lib/hatch.rb', line 122 def block @block end |
#error ⇒ Object (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 |