Class: Interdependence::ActiveModel::ValidatesWith
- Inherits:
-
Object
- Object
- Interdependence::ActiveModel::ValidatesWith
- Defined in:
- lib/interdependence/activemodel/validates_with.rb
Overview
Handler for ‘validates_with` method calls intended for ActiveModel
Makes it easy to iterate over attributes, options, and validators.
Instance Method Summary collapse
-
#attributes? ⇒ boolean
private
Any attributes present.
-
#each(&blk) ⇒ undefined
Iterate over fields and validators.
-
#initialize(*args) ⇒ undefined
constructor
private
Handle arguments intended for #validates_with.
Constructor Details
#initialize(*args) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handle arguments intended for #validates_with
41 42 43 44 |
# File 'lib/interdependence/activemodel/validates_with.rb', line 41 def initialize(*args) @validators = args = @validators. end |
Instance Method Details
#attributes? ⇒ boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Any attributes present
81 82 83 |
# File 'lib/interdependence/activemodel/validates_with.rb', line 81 def attributes? attributes.any? end |
#each(&blk) ⇒ undefined
Iterate over fields and validators
with.each do |(attribute, validator), |
puts [attribute, validator.kind, ].inspect
end
#=> [:foo, :presence, :thing=>:yes] #=> [:foo, :numericality, :thing=>:yes] #=> [:bar, :presence, :thing=>:yes] #=> [:bar, :numericality, :thing=>:yes]
69 70 71 72 73 |
# File 'lib/interdependence/activemodel/validates_with.rb', line 69 def each(&blk) attributes_with_validators .each .with_object(, &blk) end |