Class: Fleck::Core::Consumer::Validation
- Inherits:
-
Object
- Object
- Fleck::Core::Consumer::Validation
- Defined in:
- lib/fleck/core/consumer/validation.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #add_error(error_type, message) ⇒ Object
-
#initialize(name, type, value, modifier = nil, **options) ⇒ Validation
constructor
A new instance of Validation.
- #required? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(name, type, value, modifier = nil, **options) ⇒ Validation
Returns a new instance of Validation.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fleck/core/consumer/validation.rb', line 9 def initialize(name, type, value, modifier = nil, **) @name = name @type = type @modifier = modifier @value = value || [:default] @required = ([:required] == true) # default: trues @allow_blank = ([:allow_blank] != false) # default: false @min = [:min] @max = [:max] @clamp = [:clamp] || [-Float::INFINITY, Float::INFINITY] @errors = [] validate! end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/fleck/core/consumer/validation.rb', line 7 def errors @errors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/fleck/core/consumer/validation.rb', line 7 def value @value end |
Instance Method Details
#add_error(error_type, message) ⇒ Object
33 34 35 |
# File 'lib/fleck/core/consumer/validation.rb', line 33 def add_error(error_type, ) @errors << { type: 'param', name: @name, value: @value, error: error_type, message: } end |
#required? ⇒ Boolean
29 30 31 |
# File 'lib/fleck/core/consumer/validation.rb', line 29 def required? @required end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/fleck/core/consumer/validation.rb', line 25 def valid? @errors.empty? end |