Module: Dinamo::Model::Validation::ClassMethods
- Defined in:
- lib/dinamo/model/validator.rb,
lib/dinamo/model/validations/presence.rb
Instance Method Summary collapse
- #_validators ⇒ Object
- #adjust_validator_options(*args) ⇒ Object
- #validates_presence_of(*args) ⇒ Object
- #validates_with(*args, &block) ⇒ Object
- #validators ⇒ Object
Instance Method Details
#_validators ⇒ Object
64 65 66 |
# File 'lib/dinamo/model/validator.rb', line 64 def _validators @_validators ||= Hash.new { |hash, key| hash[key] = [] } end |
#adjust_validator_options(*args) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/dinamo/model/validator.rb', line 68 def (*args) = args..symbolize_keys args.flatten! [:attributes] = args end |
#validates_presence_of(*args) ⇒ Object
13 14 15 |
# File 'lib/dinamo/model/validations/presence.rb', line 13 def validates_presence_of(*args) validates_with PresenceValidator, (*args) end |
#validates_with(*args, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dinamo/model/validator.rb', line 43 def validates_with(*args, &block) = args. [:class] = self args.each do |validator_class| validator = validator_class.new(, &block) if validator.respond_to?(:attributes) && !validator.attributes.empty? validator.attributes.each do |attribute| _validators[attribute.to_sym] << validator end else _validators[nil] << validator end end end |
#validators ⇒ Object
60 61 62 |
# File 'lib/dinamo/model/validator.rb', line 60 def validators _validators.values.flatten.uniq end |