Class: Sukima
- Inherits:
-
Object
- Object
- Sukima
- Defined in:
- lib/sukima.rb,
lib/sukima/dsl.rb,
lib/sukima/constraints.rb,
lib/sukima/error_field.rb
Defined Under Namespace
Modules: Constraints Classes: Dsl, ErrorField
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
Instance Method Summary collapse
-
#initialize(**constraints, &block) ⇒ Sukima
constructor
A new instance of Sukima.
- #validate(value) ⇒ Object
Constructor Details
#initialize(**constraints, &block) ⇒ Sukima
Returns a new instance of Sukima.
10 11 12 13 |
# File 'lib/sukima.rb', line 10 def initialize(**constraints, &block) @constraints = constraints @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
8 9 10 |
# File 'lib/sukima.rb', line 8 def block @block end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
8 9 10 |
# File 'lib/sukima.rb', line 8 def constraints @constraints end |
Instance Method Details
#validate(value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sukima.rb', line 15 def validate(value) error_field = ErrorField.new return error_field if !@constraints[:nonnil] && value.nil? @constraints.each do |key, args| next if key == :required = Constraints.send(key, args, value) error_field.errors << if end Dsl.new(value, error_field).instance_exec(value, &@block) if @block && value.is_a?(@constraints[:type]) error_field end |