Class: Doodle::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/doodle.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.



177
178
179
180
# File 'lib/doodle.rb', line 177

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.



173
174
175
# File 'lib/doodle.rb', line 173

def block
  @block
end

#messageObject

Returns the value of attribute message.



172
173
174
# File 'lib/doodle.rb', line 172

def message
  @message
end