Class: SlackNotification
- Inherits:
-
Object
- Object
- SlackNotification
- Defined in:
- lib/slack_notification.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
Returns the value of attribute blocks.
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#dryrun ⇒ Object
Returns the value of attribute dryrun.
-
#fallback ⇒ Object
Returns the value of attribute fallback.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(options = {}) ⇒ SlackNotification
constructor
A new instance of SlackNotification.
- #notify! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SlackNotification
Returns a new instance of SlackNotification.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/slack_notification.rb', line 8 def initialize( = {}) @channel = validated_channel([:channel].to_s) @type = validated_type([:type]) @title = [:title] @fallback = [:fallback] @dryrun = [:dryrun] || (defined?(Rails) && Rails.env.test?) @fields = validated_fields([:fields]) @blocks = [:blocks] @footer = [:footer] end |
Instance Attribute Details
#blocks ⇒ Object
Returns the value of attribute blocks.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def blocks @blocks end |
#channel ⇒ Object
Returns the value of attribute channel.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def channel @channel end |
#dryrun ⇒ Object
Returns the value of attribute dryrun.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def dryrun @dryrun end |
#fallback ⇒ Object
Returns the value of attribute fallback.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def fallback @fallback end |
#fields ⇒ Object
Returns the value of attribute fields.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def fields @fields end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/slack_notification.rb', line 6 def type @type end |
Instance Method Details
#data ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/slack_notification.rb', line 19 def data @data = {} @data['title'] = @title || ENV['SLACK_DEFAULT_TITLE'] || 'Notification' @data['fallback'] = @fallback || @data['title'] @data['fields'] = @fields if @fields @data['color'] = slack_color @data['footer'] = if @data end |
#notify! ⇒ Object
29 30 31 |
# File 'lib/slack_notification.rb', line 29 def notify! @dryrun ? data : notifier.post(attachments: [data], blocks: @blocks) end |