Class: RestMyCase::AccusationAttorneys::Each
- Defined in:
- lib/rest_my_case/accusation_attorneys/each.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Attributes inherited from Base
Instance Method Summary collapse
- #check_validity! ⇒ Object
-
#initialize(options) ⇒ Each
constructor
A new instance of Each.
- #validate(record) ⇒ Object
-
#validate_each(record, attribute, value) ⇒ Object
Override this method in subclasses with the validation logic, adding errors to the records
errorsarray where necessary.
Constructor Details
#initialize(options) ⇒ Each
Returns a new instance of Each.
8 9 10 11 12 13 |
# File 'lib/rest_my_case/accusation_attorneys/each.rb', line 8 def initialize() @attributes = Array(.delete(:attributes)) fail ArgumentError, ":attributes cannot be blank" if @attributes.empty? super check_validity! end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/rest_my_case/accusation_attorneys/each.rb', line 6 def attributes @attributes end |
Instance Method Details
#check_validity! ⇒ Object
29 |
# File 'lib/rest_my_case/accusation_attorneys/each.rb', line 29 def check_validity!; end |
#validate(record) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rest_my_case/accusation_attorneys/each.rb', line 15 def validate(record) attributes.each do |attribute| value = record.respond_to?(attribute) ? record.send(attribute) : nil next if (value.nil? && [:allow_nil]) || (Helpers.blank?(value) && [:allow_blank]) validate_each(record, attribute, value) end end |
#validate_each(record, attribute, value) ⇒ Object
Override this method in subclasses with the validation logic, adding errors to the records errors array where necessary.
25 26 27 |
# File 'lib/rest_my_case/accusation_attorneys/each.rb', line 25 def validate_each(record, attribute, value) fail NotImplementedError, "Subclasses must implement a validate_each(record, attribute, value) method" end |