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.
46 47 48 49 |
# File 'lib/emailbutler/adapters/active_record.rb', line 46 def initialize(={}) @name = .fetch(:name, :active_record) = .fetch(:message_class) { Emailbutler::Message } end |
Instance Attribute Details
#message_class ⇒ Object (readonly)
Public: The name of the adapter.
40 41 42 |
# File 'lib/emailbutler/adapters/active_record.rb', line 40 def end |
#name ⇒ Object (readonly)
Public: The name of the adapter.
40 41 42 |
# File 'lib/emailbutler/adapters/active_record.rb', line 40 def name @name end |
Instance Method Details
#build_message(args = {}) ⇒ Object
Public: Builds a message.
52 53 54 |
# File 'lib/emailbutler/adapters/active_record.rb', line 52 def (args={}) .new(args) end |
#count_messages_by_status ⇒ Object
Public: Groups messages by status and count them.
79 80 81 |
# File 'lib/emailbutler/adapters/active_record.rb', line 79 def .group(:status).count end |
#destroy_message(message) ⇒ Object
Public: Destroy the message.
97 98 99 |
# File 'lib/emailbutler/adapters/active_record.rb', line 97 def () .destroy end |
#find_message_by(args = {}) ⇒ Object
Public: Finds message by args.
67 68 69 |
# File 'lib/emailbutler/adapters/active_record.rb', line 67 def (args={}) .find_by(args) end |
#find_messages_by(args = {}) ⇒ Object
Public: Finds messages by args.
84 85 86 |
# File 'lib/emailbutler/adapters/active_record.rb', line 84 def (args={}) .where(args).order(created_at: :desc) end |
#resend_message(message) ⇒ Object
Public: Resends the message.
89 90 91 92 93 94 |
# File 'lib/emailbutler/adapters/active_record.rb', line 89 def () ::ActiveRecord::Base.transaction do .destroy () end end |
#save_message(message) ⇒ Object
Public: Saves the message.
62 63 64 |
# File 'lib/emailbutler/adapters/active_record.rb', line 62 def () .save end |
#set_message_attribute(message, attribute, value) ⇒ Object
Public: Sets attribute with value for the message.
57 58 59 |
# File 'lib/emailbutler/adapters/active_record.rb', line 57 def (, attribute, value) [attribute] = value end |
#update_message(message, args = {}) ⇒ Object
Public: Updates the message.
72 73 74 75 76 |
# File 'lib/emailbutler/adapters/active_record.rb', line 72 def (, args={}) .update(args) if ..nil? || args[:timestamp] > . rescue ::ActiveRecord::StaleObjectError (.reload, args) end |