Class: Doodle::Validation
- Inherits:
-
Object
- Object
- Doodle::Validation
- Defined in:
- lib/doodle/validation.rb
Overview
A Validation represents a validation rule applied to the instance after initialization. Generated using the Doodle::BaseMethods#must directive.
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(message = 'not be nil', &block) ⇒ Validation
constructor
create a new validation rule.
Constructor Details
#initialize(message = 'not be nil', &block) ⇒ Validation
create a new validation rule. This is typically a result of calling must
so the text should work following the word “must”, e.g. “must not be nil”, “must be >= 10”, etc.
10 11 12 13 |
# File 'lib/doodle/validation.rb', line 10 def initialize( = 'not be nil', &block) @message = @block = block_given? ? block : proc { |x| !self.nil? } end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
6 7 8 |
# File 'lib/doodle/validation.rb', line 6 def block @block end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/doodle/validation.rb', line 5 def @message end |