Class: SlackSender::Notifier::NotificationDSL
- Inherits:
-
Object
- Object
- SlackSender::Notifier::NotificationDSL
- Defined in:
- lib/slack_sender/notifier/notification_dsl.rb
Overview
Builder DSL for the notify do ... end block.
Collects routing, payload, and condition settings into a NotificationDefinition.
Constant Summary collapse
- PAYLOAD_FIELDS =
%i[text blocks attachments icon_emoji thread_ts files slack_options].freeze
- PASSTHROUGH_FIELDS =
Fields that modify a message rather than constitute its content. A notify block that sets only these has no real payload, so they don't count toward the "Missing payload" check.
%i[slack_options].freeze
Instance Method Summary collapse
-
#build ⇒ Object
--- Build ---.
-
#channel(value = nil, &block) ⇒ Object
--- Routing ---.
- #channels(*values, &block) ⇒ Object
-
#initialize ⇒ NotificationDSL
constructor
A new instance of NotificationDSL.
- #only_if(value = nil, &block) ⇒ Object
- #profile(value = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ NotificationDSL
Returns a new instance of NotificationDSL.
14 15 16 17 18 19 |
# File 'lib/slack_sender/notifier/notification_dsl.rb', line 14 def initialize @channels = [] @profile = nil @condition = nil @payload = {} end |
Instance Method Details
#build ⇒ Object
--- Build ---
53 54 55 56 57 58 59 60 |
# File 'lib/slack_sender/notifier/notification_dsl.rb', line 53 def build NotificationDefinition.new( channels: @channels, profile: @profile, condition: @condition, payload: @payload, ) end |
#channel(value = nil, &block) ⇒ Object
--- Routing ---
23 24 25 |
# File 'lib/slack_sender/notifier/notification_dsl.rb', line 23 def channel(value = nil, &block) @channels << (block || value) end |
#channels(*values, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/slack_sender/notifier/notification_dsl.rb', line 27 def channels(*values, &block) if block @channels << block else values.flatten.each { |v| @channels << v } end end |
#only_if(value = nil, &block) ⇒ Object
47 48 49 |
# File 'lib/slack_sender/notifier/notification_dsl.rb', line 47 def only_if(value = nil, &block) @condition = block || value end |
#profile(value = nil, &block) ⇒ Object
43 44 45 |
# File 'lib/slack_sender/notifier/notification_dsl.rb', line 43 def profile(value = nil, &block) @profile = block || value end |