Class: ActionMessenger::Base
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- ActionMessenger::Base
- Includes:
- AbstractController::Helpers, AbstractController::Logger, AbstractController::Rendering, Rescuable, ActionView::Layouts
- Defined in:
- lib/action_messenger/base.rb
Defined Under Namespace
Classes: DeliveryLog
Instance Attribute Summary collapse
-
#caller_method_name ⇒ Object
readonly
end class << self.
-
#deliveries ⇒ Object
readonly
end class << self.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#message_to_slack(channel:, options: {}) ⇒ Object
message to slack.
-
#upload_file_to_slack(channels:, file:, options: {}) ⇒ Object
upload file to slack.
Methods included from Rescuable
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
39 40 41 |
# File 'lib/action_messenger/base.rb', line 39 def initialize @deliveries = [] end |
Instance Attribute Details
#caller_method_name ⇒ Object (readonly)
end class << self
35 36 37 |
# File 'lib/action_messenger/base.rb', line 35 def caller_method_name @caller_method_name end |
#deliveries ⇒ Object (readonly)
end class << self
35 36 37 |
# File 'lib/action_messenger/base.rb', line 35 def deliveries @deliveries end |
Class Method Details
.logger ⇒ Object
15 16 17 |
# File 'lib/action_messenger/base.rb', line 15 def logger ActionMessenger.config.logger || (defined?(Rails) ? Rails.logger : nil) end |
Instance Method Details
#message_to_slack(channel:, options: {}) ⇒ Object
message to slack
ex. message_to_slack(channel: ‘#general’, options: ‘sample’)
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/action_messenger/base.rb', line 51 def (channel:, options: {}) @caller_method_name = caller[0][/`([^']*)'/, 1] = apply_defaults() = nil ActiveSupport::Notifications.instrument('message_to_slack.action_messenger', channel: channel, body: [:text]) do = slack_client.(channel, ) end ensure self.deliveries << DeliveryLog.new(__method__, channel, ) end |
#upload_file_to_slack(channels:, file:, options: {}) ⇒ Object
upload file to slack
70 71 72 73 74 75 76 77 78 |
# File 'lib/action_messenger/base.rb', line 70 def upload_file_to_slack(channels: ,file: ,options: {}) upload_file = nil ActiveSupport::Notifications.instrument('upload_file_to_slack.action_messenger', channels: channels) do upload_file = slack_client.upload_file(channels, file, ) end upload_file ensure self.deliveries << DeliveryLog.new(__method__, channels, upload_file) end |