Class: Doodle::Validation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(message = 'not be nil', &block)
  @message = message
  @block = block_given? ? block : proc { |x| !self.nil? }
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



6
7
8
# File 'lib/doodle/validation.rb', line 6

def block
  @block
end

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/doodle/validation.rb', line 5

def message
  @message
end