Class: SlackInteractiveClient::Message
- Inherits:
-
Object
- Object
- SlackInteractiveClient::Message
- Defined in:
- lib/slack_interactive_client/message.rb,
lib/slack_interactive_client/message/compilation.rb
Defined Under Namespace
Classes: Compilation
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#environment(env) ⇒ Object
readonly
Returns the value of attribute environment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tagged_users ⇒ Object
readonly
Returns the value of attribute tagged_users.
Class Method Summary collapse
- .compile(template_name, args = {}) ⇒ Object
- .define(&block) ⇒ Object
- .template(name, &block) ⇒ Object
Instance Method Summary collapse
- #channel(channel) ⇒ Object
- #compile(args = {}) ⇒ Object
- #csv_data(bool = false) ⇒ Object
-
#initialize ⇒ Message
constructor
A new instance of Message.
- #list_item(item) ⇒ Object
- #list_section(&block) ⇒ Object
- #markdown_section(markdown = nil, &block) ⇒ Object
- #mention(*users) ⇒ Object
- #reset_message_blocks ⇒ Object
- #template(name, &block) ⇒ Object
- #text(text = nil, &block) ⇒ Object
- #title(title = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
33 34 35 36 37 38 39 40 |
# File 'lib/slack_interactive_client/message.rb', line 33 def initialize @blocks = [] @environment = nil @channels = [] @tagged_users = [] @csv_data_block = [] @list_items = [] end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
31 32 33 |
# File 'lib/slack_interactive_client/message.rb', line 31 def blocks @blocks end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
31 32 33 |
# File 'lib/slack_interactive_client/message.rb', line 31 def channels @channels end |
#environment(env) ⇒ Object (readonly)
Returns the value of attribute environment.
31 32 33 |
# File 'lib/slack_interactive_client/message.rb', line 31 def environment @environment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/slack_interactive_client/message.rb', line 31 def name @name end |
#tagged_users ⇒ Object (readonly)
Returns the value of attribute tagged_users.
31 32 33 |
# File 'lib/slack_interactive_client/message.rb', line 31 def tagged_users @tagged_users end |
Class Method Details
.compile(template_name, args = {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/slack_interactive_client/message.rb', line 16 def compile(template_name, args = {}) template = @templates.fetch(template_name) do raise ArgumentError, "Template #{template_name} not defined" end template. template.compile(args) end |
.define(&block) ⇒ Object
11 12 13 14 |
# File 'lib/slack_interactive_client/message.rb', line 11 def define(&block) @templates ||= {} instance_exec(&block) end |
.template(name, &block) ⇒ Object
24 25 26 27 28 |
# File 'lib/slack_interactive_client/message.rb', line 24 def template(name, &block) instance = new instance.instance_eval(&block) @templates[name] = instance end |
Instance Method Details
#channel(channel) ⇒ Object
71 72 73 |
# File 'lib/slack_interactive_client/message.rb', line 71 def channel(channel) @channels << channel end |
#compile(args = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/slack_interactive_client/message.rb', line 85 def compile(args = {}) construct_environment_block if @environment construct_title_block(args) if @title_block construct_text_block(args) if @text_block construct_markdown_block(args) if @markdown_block construct_list_block(args) if @list_block construct_csv(args) if @include_csv_data add_user_mentions if @tagged_users.any? = { blocks: @blocks, channel: args[:channel] || @channels, } ::SlackInteractiveClient::Message::Compilation.new( , @include_csv_data, @csv_data ) end |
#csv_data(bool = false) ⇒ Object
81 82 83 |
# File 'lib/slack_interactive_client/message.rb', line 81 def csv_data(bool = false) @include_csv_data = bool end |
#list_item(item) ⇒ Object
63 64 65 |
# File 'lib/slack_interactive_client/message.rb', line 63 def list_item(item) @list_items << item end |
#list_section(&block) ⇒ Object
59 60 61 |
# File 'lib/slack_interactive_client/message.rb', line 59 def list_section(&block) @list_block = block end |
#markdown_section(markdown = nil, &block) ⇒ Object
55 56 57 |
# File 'lib/slack_interactive_client/message.rb', line 55 def markdown_section(markdown = nil, &block) @markdown_block = markdown.nil? ? block : Proc.new {|x| markdown } end |
#mention(*users) ⇒ Object
75 76 77 78 79 |
# File 'lib/slack_interactive_client/message.rb', line 75 def mention(*users) # Format the user mention strings @tagged_users = users.flatten @user_mentions = users.flatten.join(' ') end |
#reset_message_blocks ⇒ Object
106 107 108 109 |
# File 'lib/slack_interactive_client/message.rb', line 106 def @blocks = [] @list_items = [] end |
#template(name, &block) ⇒ Object
42 43 44 45 |
# File 'lib/slack_interactive_client/message.rb', line 42 def template(name, &block) @name = name instance_eval(&block) if block_given? end |
#text(text = nil, &block) ⇒ Object
47 48 49 |
# File 'lib/slack_interactive_client/message.rb', line 47 def text(text = nil , &block) @text_block = text.nil? ? block : Proc.new {|x| text } end |
#title(title = nil, &block) ⇒ Object
51 52 53 |
# File 'lib/slack_interactive_client/message.rb', line 51 def title(title = nil , &block) @title_block = title.nil? ? block : Proc.new {|x| title } end |