class SlackMessaging::Setup
Public Class Methods
execute()
click to toggle source
rubocop:disable Style/ConditionalAssignment
# File lib/slack_messaging/setup.rb, line 7 def execute if config_file_exists? answer = highline.ask_yes_no( "It looks like the #{default_config} file already exists. Do you wish to replace it? (y/n)", { required: true } ) else answer = true end create_or_update_config_file(ask_config_questions) if answer end
Private Class Methods
ask_config_questions()
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/slack_messaging/setup.rb, line 43 def ask_config_questions answers = {} answers[:webhook_url] = ask_question( "What is your Slack webhook URL? If you don't have one yet, please navigate" \ ' to https://api.slack.com/messaging/webhooks to create one, and then come back' \ ' here and paste it in the Terminal.', nil, required: true ) answers[:channel] = ask_question( 'What slack channel do you wish to post to? (default is "#general")', '#general' ) answers[:username] = ask_question( "What slack username do you wish to post as? (default is \"Let's Get Quoty\")", "Let's Get Quoty" ) answers[:icon_emoji] = ask_question( 'What emoji would you like to post with (include the colons at the beginning and end' \ ' of the emoji name)? (default is ":mailbox_with_mail:")', ':mailbox_with_mail:' ) answers end
ask_question(prompt, default, required: false)
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/slack_messaging/setup.rb, line 74 def ask_question(prompt, default, required: false) highline.ask(prompt, { default: default, required: required }) end
config_file_exists?()
click to toggle source
# File lib/slack_messaging/setup.rb, line 38 def config_file_exists? File.exist?(default_config) end
create_or_update_config_file(answers)
click to toggle source
rubocop:enable Style/ConditionalAssignment
# File lib/slack_messaging/setup.rb, line 21 def create_or_update_config_file(answers) contents = generate_config_file(answers) puts "Creating or updating your #{default_config} file..." File.open(default_config, 'w') { |file| file.puts contents } puts 'Done!' end
default_config()
click to toggle source
# File lib/slack_messaging/setup.rb, line 82 def default_config SlackMessaging::DefaultPaths.config end
generate_config_file(answers)
click to toggle source
# File lib/slack_messaging/setup.rb, line 28 def generate_config_file(answers) file_contents = ''.dup file_contents << "slack:\n" file_contents << " channel: #{answers[:channel].tr('#', '').strip}\n" file_contents << " username: #{answers[:username].strip}\n" file_contents << " webhook_url: #{answers[:webhook_url].strip}\n" file_contents << " icon_emoji: '#{answers[:icon_emoji].strip}'" file_contents end
highline()
click to toggle source
# File lib/slack_messaging/setup.rb, line 78 def highline @highline ||= HighlineWrapper.new end