Class: BazaModels::Validators::BaseValidator
- Inherits:
-
Object
- Object
- BazaModels::Validators::BaseValidator
- Defined in:
- lib/baza_models/validators/base_validator.rb
Direct Known Subclasses
ConfirmationValidator, FormatValidator, LengthValidator, PresenceValidator, UniquenessValidator
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
Instance Method Summary collapse
- #fire?(model) ⇒ Boolean
-
#initialize(attribute_name, args) ⇒ BaseValidator
constructor
A new instance of BaseValidator.
Constructor Details
#initialize(attribute_name, args) ⇒ BaseValidator
Returns a new instance of BaseValidator.
4 5 6 7 |
# File 'lib/baza_models/validators/base_validator.rb', line 4 def initialize(attribute_name, args) @attribute_name = attribute_name @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
2 3 4 |
# File 'lib/baza_models/validators/base_validator.rb', line 2 def args @args end |
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
2 3 4 |
# File 'lib/baza_models/validators/base_validator.rb', line 2 def attribute_name @attribute_name end |
Instance Method Details
#fire?(model) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/baza_models/validators/base_validator.rb', line 9 def fire?(model) result = true if @args[:if] if @args.fetch(:if).is_a?(Symbol) result = model.__send__(@args.fetch(:if)) else raise "Unknown 'if'-argument: #{@args[:if]} (#{@args[:if].class.name})" end end result end |