Class: Syncano::Resources::Notifications::Base
- Defined in:
- lib/syncano/resources/notifications/base.rb
Overview
Base notification class used for inheritance
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.all(client, scope_parameters = {}, conditions = {}) ⇒ Array
Wrapper for api “get” method Returns all objects from Syncano.
-
.create(client, attributes) ⇒ Syncano::Resources::Base
Wrapper for api “send” method Creates object in Syncano.
-
.instantize_notification(client, packet) ⇒ Syncano::Notifications::Base
Proxy method for creating instance of proper subclass.
Instance Method Summary collapse
-
#initialize(client, attributes) ⇒ Base
constructor
Constructor for Syncano::Notifications::Base object.
Methods inherited from Base
#[], #[]=, #batch, batch_create, #batch_destroy, #batch_save, #batch_update, count, #destroy, #destroyed?, find, #new_record?, #reload!, #save, #saved?, #update
Constructor Details
#initialize(client, attributes) ⇒ Base
Constructor for Syncano::Notifications::Base object
10 11 12 13 14 15 16 17 |
# File 'lib/syncano/resources/notifications/base.rb', line 10 def initialize(client, attributes) if attributes.is_a?(::Syncano::Packets::Base) super(client, {}) self.attributes = { source: attributes.source, target: attributes.target, data: attributes.data } else super(client, attributes) end end |
Class Method Details
.all(client, scope_parameters = {}, conditions = {}) ⇒ Array
Wrapper for api “get” method Returns all objects from Syncano
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/syncano/resources/notifications/base.rb', line 43 def self.all(client, scope_parameters = {}, conditions = {}) mapping = { new: ::Syncano::Resources::Notifications::Create, change: ::Syncano::Resources::Notifications::Update, delete: ::Syncano::Resources::Notifications::Destroy, message: ::Syncano::Resources::Notifications::Message } response = perform_all(client, scope_parameters, conditions) response.data.to_a.collect do |attributes| type = attributes.delete(:type) mapping[type.to_sym].new(client, attributes.merge(scope_parameters)) end end |
.create(client, attributes) ⇒ Syncano::Resources::Base
Wrapper for api “send” method Creates object in Syncano
63 64 65 66 |
# File 'lib/syncano/resources/notifications/base.rb', line 63 def self.create(client, attributes) perform_create(client, nil, attributes) ::Syncano::Resources::Notifications::Message.new(client, map_to_scope_parameters(attributes)) end |
.instantize_notification(client, packet) ⇒ Syncano::Notifications::Base
Proxy method for creating instance of proper subclass
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/syncano/resources/notifications/base.rb', line 23 def self.instantize_notification(client, packet) if packet. ::Syncano::Resources::Notifications::Message.new(client, packet) else mapping = { new: ::Syncano::Resources::Notifications::Create, change: ::Syncano::Resources::Notifications::Update, delete: ::Syncano::Resources::Notifications::Destroy } mapping[packet.type.to_sym].new(client, packet) end end |