Class: Nemo::MetaObject::ValidationRule

Inherits:
Object
  • Object
show all
Extended by:
Util::Accessors
Defined in:
lib/nemo/metaobject/validation.rb

Instance Method Summary collapse

Methods included from Util::Accessors

bool_accessor, call_accessor, proc_accessor

Constructor Details

#initialize(&block) ⇒ ValidationRule

Returns a new instance of ValidationRule.



23
24
25
26
# File 'lib/nemo/metaobject/validation.rb', line 23

def initialize(&block)
  @error_string = 'not valid'
  @rule = block
end

Instance Method Details

#valid?(value) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/nemo/metaobject/validation.rb', line 28

def valid?(value)
  begin Nemo::Util.to_bool(@rule.call(value)) if @rule rescue false end
end