Class: Emailbutler::Adapters::ActiveRecord
- Inherits:
-
Object
- Object
- Emailbutler::Adapters::ActiveRecord
- Includes:
- Helpers
- Defined in:
- lib/emailbutler/adapters/active_record.rb
Defined Under Namespace
Classes: Model
Instance Attribute Summary collapse
-
#message_class ⇒ Object
readonly
Public: The name of the adapter.
-
#name ⇒ Object
readonly
Public: The name of the adapter.
Instance Method Summary collapse
-
#build_message(args = {}) ⇒ Object
Public: Builds a message.
-
#count_messages_by_status ⇒ Object
Public: Groups messages by status and count them.
-
#destroy_message(message) ⇒ Object
Public: Destroy the message.
-
#find_message_by(args = {}) ⇒ Object
Public: Finds message by args.
-
#find_messages_by(args = {}) ⇒ Object
Public: Finds messages by args.
-
#initialize(options = {}) ⇒ ActiveRecord
constructor
Public: Initialize a new ActiveRecord adapter instance.
-
#resend_message(message) ⇒ Object
Public: Resends the message.
-
#save_message(message) ⇒ Object
Public: Saves the message.
-
#set_message_attribute(message, attribute, value) ⇒ Object
Public: Sets attribute with value for the message.
-
#update_message(message, args = {}) ⇒ Object
Public: Updates the message.
Constructor Details
#initialize(options = {}) ⇒ ActiveRecord
Public: Initialize a new ActiveRecord adapter instance.
name - The Symbol name for this adapter. Optional (default :active_record) message_class - The AR class responsible for the messages table.
42 43 44 45 |
# File 'lib/emailbutler/adapters/active_record.rb', line 42 def initialize(={}) @name = .fetch(:name, :active_record) @message_class = .fetch(:message_class) { Emailbutler::Message } end |
Instance Attribute Details
#message_class ⇒ Object (readonly)
Public: The name of the adapter.
36 37 38 |
# File 'lib/emailbutler/adapters/active_record.rb', line 36 def @message_class end |
#name ⇒ Object (readonly)
Public: The name of the adapter.
36 37 38 |
# File 'lib/emailbutler/adapters/active_record.rb', line 36 def name @name end |
Instance Method Details
#build_message(args = {}) ⇒ Object
Public: Builds a message.
48 49 50 |
# File 'lib/emailbutler/adapters/active_record.rb', line 48 def (args={}) @message_class.new(args) end |
#count_messages_by_status ⇒ Object
Public: Groups messages by status and count them.
75 76 77 |
# File 'lib/emailbutler/adapters/active_record.rb', line 75 def @message_class.group(:status).count end |
#destroy_message(message) ⇒ Object
Public: Destroy the message.
93 94 95 |
# File 'lib/emailbutler/adapters/active_record.rb', line 93 def () .destroy end |
#find_message_by(args = {}) ⇒ Object
Public: Finds message by args.
63 64 65 |
# File 'lib/emailbutler/adapters/active_record.rb', line 63 def (args={}) @message_class.find_by(args) end |
#find_messages_by(args = {}) ⇒ Object
Public: Finds messages by args.
80 81 82 |
# File 'lib/emailbutler/adapters/active_record.rb', line 80 def (args={}) @message_class.where(args).order(created_at: :desc) end |
#resend_message(message) ⇒ Object
Public: Resends the message.
85 86 87 88 89 90 |
# File 'lib/emailbutler/adapters/active_record.rb', line 85 def () ::ActiveRecord::Base.transaction do .destroy () end end |
#save_message(message) ⇒ Object
Public: Saves the message.
58 59 60 |
# File 'lib/emailbutler/adapters/active_record.rb', line 58 def () .save end |
#set_message_attribute(message, attribute, value) ⇒ Object
Public: Sets attribute with value for the message.
53 54 55 |
# File 'lib/emailbutler/adapters/active_record.rb', line 53 def (, attribute, value) [attribute] = value end |
#update_message(message, args = {}) ⇒ Object
Public: Updates the message.
68 69 70 71 72 |
# File 'lib/emailbutler/adapters/active_record.rb', line 68 def (, args={}) .update(args) if ..nil? || args[:timestamp] > . rescue ::ActiveRecord::StaleObjectError (.reload, args) end |