Class: RTPush::PresenceValidator
- Inherits:
-
Object
- Object
- RTPush::PresenceValidator
- Defined in:
- lib/rtpush/adapters/base_adapter.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #exist(record) ⇒ Object
-
#initialize(*attributes) ⇒ PresenceValidator
constructor
A new instance of PresenceValidator.
- #validate(record) ⇒ Object
Constructor Details
#initialize(*attributes) ⇒ PresenceValidator
Returns a new instance of PresenceValidator.
36 37 38 |
# File 'lib/rtpush/adapters/base_adapter.rb', line 36 def initialize(*attributes) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
34 35 36 |
# File 'lib/rtpush/adapters/base_adapter.rb', line 34 def attributes @attributes end |
Instance Method Details
#exist(record) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/rtpush/adapters/base_adapter.rb', line 51 def exist(record) @attributes.each do |attribute| data = ENV[attribute.to_s] if data.nil? || data.empty? record.errors << ["#{attribute} can't be empty"] end end end |
#validate(record) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rtpush/adapters/base_adapter.rb', line 40 def validate(record) begin @attributes.each do |attribute| data = record.send(attribute) if data.nil? || data.empty? record.errors << ["#{attribute} can't be blank"] end end end end |