Class: Ucasy::Validators::Validate
- Defined in:
- lib/ucasy/validators/validate.rb
Instance Method Summary collapse
- #call ⇒ Object
- #errors ⇒ Object
-
#initialize(klass, attributes) ⇒ Validate
constructor
A new instance of Validate.
- #invalid? ⇒ Boolean
- #message ⇒ Object
- #to_context ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from Callable
Constructor Details
#initialize(klass, attributes) ⇒ Validate
3 4 5 6 |
# File 'lib/ucasy/validators/validate.rb', line 3 def initialize(klass, attributes) @klass = klass @attributes = attributes end |
Instance Method Details
#call ⇒ Object
8 9 10 11 12 |
# File 'lib/ucasy/validators/validate.rb', line 8 def call @validator = @klass.new(@attributes) if @klass.present? self end |
#errors ⇒ Object
30 31 32 |
# File 'lib/ucasy/validators/validate.rb', line 30 def errors @validator&.errors || [] end |
#invalid? ⇒ Boolean
26 27 28 |
# File 'lib/ucasy/validators/validate.rb', line 26 def invalid? !valid? end |
#message ⇒ Object
14 15 16 |
# File 'lib/ucasy/validators/validate.rb', line 14 def @validator.try(:message_error) end |
#to_context ⇒ Object
18 19 20 |
# File 'lib/ucasy/validators/validate.rb', line 18 def to_context @validator.try(:to_context) || {} end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/ucasy/validators/validate.rb', line 22 def valid? @validator&.valid? || false end |