Class: RoboPigeon::Dsl::Slack

Inherits:
SlackRoot show all
Defined in:
lib/robopigeon/slack/dsl.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SlackRoot

#api_key, #emoji, #enabled, #name

Methods inherited from Base

#method_missing, #respond_to_missing?

Methods inherited from Job

#gitlab, #jenkins, #jira, #slack

Methods included from Helpers

#skip

Methods included from Helpers::Markdown

#confluence_from_md, #html_from_md, #jira_from_md, #slack_from_md

Methods included from Helpers::GitLab

#deployment_code_change_stats, #deployment_diff_link, #deployment_ref, #deployment_sha, #deployment_shortlog, #deployment_time, #environment_link, #tickets_in_log_since_deployment_to

Methods included from Helpers::Slack

#slack_name_for, #slack_user_for, #slack_user_group

Methods included from Helpers::Jira

#jira_last_created_ticket, #jira_last_created_ticket_link, #jira_last_created_ticket_slack_link, #jira_slack_link

Methods included from Helpers::Git

#changed_since?, #git_branch_merged_source, #git_branch_merged_target, #git_committer_email, #git_committer_name, #git_merger_email, #git_merger_name

Constructor Details

#initializeSlack

Returns a new instance of Slack.



44
45
46
# File 'lib/robopigeon/slack/dsl.rb', line 44

def initialize
  self.message = RoboPigeon::Slack::Message.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RoboPigeon::Dsl::Base

Instance Attribute Details

#messageObject

Returns the value of attribute message.



32
33
34
# File 'lib/robopigeon/slack/dsl.rb', line 32

def message
  @message
end

Class Method Details

.run(&block) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/robopigeon/slack/dsl.rb', line 34

def self.run(&block)
  if RoboPigeon::Slack::Client.enabled
    slack = RoboPigeon::Dsl::Slack.new
    slack.instance_eval(&block)
    slack.message.send!
  else
    puts 'Slack is disabled, please remove `enabled false` from your global slack config'
  end
end

Instance Method Details

#attachment(&block) ⇒ Object



64
65
66
# File 'lib/robopigeon/slack/dsl.rb', line 64

def attachment(&block)
  message.attachments.push(RoboPigeon::Dsl::SlackAttachment.run(&block))
end

#channel(channel) ⇒ Object



54
55
56
# File 'lib/robopigeon/slack/dsl.rb', line 54

def channel(channel)
  message.channels.push(channel)
end

#text(text) ⇒ Object



59
60
61
# File 'lib/robopigeon/slack/dsl.rb', line 59

def text(text)
  message.text = text
end

#user(*user) ⇒ Object



49
50
51
# File 'lib/robopigeon/slack/dsl.rb', line 49

def user(*user)
  message.users.push(RoboPigeon::Slack::Client.get_user(user).try(:id))
end