Class: FirebaseCloudMessenger::FirebaseObject
- Inherits:
-
Object
- Object
- FirebaseCloudMessenger::FirebaseObject
- Defined in:
- lib/firebase_cloud_messenger/firebase_object.rb
Direct Known Subclasses
Android::Config, Android::Notification, Apns::ApnsObject, Message, Notification, Webpush::Config, Webpush::Notification
Instance Method Summary collapse
-
#initialize(data, fields) ⇒ FirebaseObject
constructor
A new instance of FirebaseObject.
- #to_h ⇒ Object
Constructor Details
#initialize(data, fields) ⇒ FirebaseObject
Returns a new instance of FirebaseObject.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/firebase_cloud_messenger/firebase_object.rb', line 3 def initialize(data, fields) data = data.dup @fields = fields fields.each do |field| send(:"#{field}=", data.delete(field)) end if data.any? raise ArgumentError, "Keys must be one on #{fields.inspect}" end end |
Instance Method Details
#to_h ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/firebase_cloud_messenger/firebase_object.rb', line 16 def to_h fields.each_with_object({}) do |field, object_hash| val = send(field) next if val.nil? val = val.to_h if val.is_a?(FirebaseObject) object_hash[field] = val end end |