From 4a170c799ad201f4d33afc4ae0c8d2287e39dd27 Mon Sep 17 00:00:00 2001 From: kaiomagalhaes Date: Tue, 8 Dec 2015 11:46:03 -0200 Subject: [PATCH 1/5] add option to disable via rails config --- lib/slacked/slack_post.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/slacked/slack_post.rb b/lib/slacked/slack_post.rb index d44b0c1..acd4d12 100644 --- a/lib/slacked/slack_post.rb +++ b/lib/slacked/slack_post.rb @@ -8,7 +8,7 @@ module Slacked class << self def post message = ENV[SLACK_DEFAULT_MESSAGE_KEY] - return false if message.nil? || message.empty? + return false if message.nil? || message.empty? || disabled? notifier = slack_notifier notifier.ping message, SLACK_CONFIG end @@ -25,5 +25,15 @@ def post_async message def slack_notifier webhook_url = ENV[SLACK_WEBHOOK_URL_KEY] Slack::Notifier.new webhook_url end + + def rails? + defined?(Rails) + end + + def disabled? + return false if rails? + rails_config = Rails.application.config + rails_config.config.respond_to?(:slacked_disabled) && rails_config.slacked_disabled + end end end From c3c28cd49a144c3b9974efc5b174dead4622a804 Mon Sep 17 00:00:00 2001 From: kaiomagalhaes Date: Tue, 8 Dec 2015 11:59:59 -0200 Subject: [PATCH 2/5] Add @locky as a contributor, change version and change bundle min version --- lib/slacked/slack_post.rb | 12 ++++++------ lib/slacked/version.rb | 2 +- slacked.gemspec | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/slacked/slack_post.rb b/lib/slacked/slack_post.rb index acd4d12..78ecd3f 100644 --- a/lib/slacked/slack_post.rb +++ b/lib/slacked/slack_post.rb @@ -21,6 +21,12 @@ def post_async message end end + def disabled? + return false if rails? + rails_config = Rails.application.config + rails_config.config.respond_to?(:slacked_disabled) && rails_config.slacked_disabled + end + private def slack_notifier webhook_url = ENV[SLACK_WEBHOOK_URL_KEY] Slack::Notifier.new webhook_url @@ -29,11 +35,5 @@ def slack_notifier webhook_url = ENV[SLACK_WEBHOOK_URL_KEY] def rails? defined?(Rails) end - - def disabled? - return false if rails? - rails_config = Rails.application.config - rails_config.config.respond_to?(:slacked_disabled) && rails_config.slacked_disabled - end end end diff --git a/lib/slacked/version.rb b/lib/slacked/version.rb index b0ce836..41bcadb 100644 --- a/lib/slacked/version.rb +++ b/lib/slacked/version.rb @@ -1,3 +1,3 @@ module Slacked - VERSION = "0.7.0" + VERSION = "0.9.0" end diff --git a/slacked.gemspec b/slacked.gemspec index 9cd3bde..a249118 100644 --- a/slacked.gemspec +++ b/slacked.gemspec @@ -6,7 +6,7 @@ require 'slacked/version' Gem::Specification.new do |spec| spec.name = "slacked" spec.version = Slacked::VERSION - spec.authors = ["sean"] + spec.authors = ["Sean", "Kaio Magalhães", "Locky"] spec.email = ["seathony@gmail.com"] spec.summary = %q{A super simple and easy way to send notifications to Slack from your Rails application.} @@ -32,7 +32,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.10' + spec.add_development_dependency 'bundler', '~> 1.9.5' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec' spec.add_development_dependency 'rspec-mocks' From 8535818ef822dd4ae3c4a8ed7a82bd4bc733e45e Mon Sep 17 00:00:00 2001 From: kaiomagalhaes Date: Tue, 8 Dec 2015 12:04:02 -0200 Subject: [PATCH 3/5] small fix and reverting bundle version --- lib/slacked/slack_post.rb | 2 +- slacked.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/slacked/slack_post.rb b/lib/slacked/slack_post.rb index 78ecd3f..04ed97e 100644 --- a/lib/slacked/slack_post.rb +++ b/lib/slacked/slack_post.rb @@ -22,7 +22,7 @@ def post_async message end def disabled? - return false if rails? + return false unless rails? rails_config = Rails.application.config rails_config.config.respond_to?(:slacked_disabled) && rails_config.slacked_disabled end diff --git a/slacked.gemspec b/slacked.gemspec index a249118..d383fac 100644 --- a/slacked.gemspec +++ b/slacked.gemspec @@ -32,7 +32,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 1.9.5' + spec.add_development_dependency 'bundler', '~> 1.10' spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rspec' spec.add_development_dependency 'rspec-mocks' From ba504b3ad4fa251e14c331da64a60640b30b1557 Mon Sep 17 00:00:00 2001 From: kaiomagalhaes Date: Tue, 8 Dec 2015 12:13:43 -0200 Subject: [PATCH 4/5] small fix --- lib/slacked/slack_post.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/slacked/slack_post.rb b/lib/slacked/slack_post.rb index 04ed97e..3fbff48 100644 --- a/lib/slacked/slack_post.rb +++ b/lib/slacked/slack_post.rb @@ -24,7 +24,7 @@ def post_async message def disabled? return false unless rails? rails_config = Rails.application.config - rails_config.config.respond_to?(:slacked_disabled) && rails_config.slacked_disabled + rails_config.respond_to?(:slacked_disabled) && rails_config.slacked_disabled end private From b03c7e186bfb89f6828eab5cb5b3613c1496b181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaio=20Cristian=20Costa=20Porto=20de=20Magalh=C3=A3es?= Date: Tue, 8 Dec 2015 12:22:14 -0200 Subject: [PATCH 5/5] update readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f061b92..53cfc87 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This is a super simple Slack integration for Rails. A use case for this would be Are there other gems that provide similar functionality? Yes. Do some of them provide more flexibility? Yes. The point of this was to make installing and integrating a 30 second process. +This gem can be used with a rails application and enabled/disabled based on the environment config as you may see below + ## Getting Started Add this line to your application's Gemfile: @@ -73,6 +75,15 @@ class Post < ActiveRecord::Base end ``` +## Using with rails +If you are using this gem inside a rails application you can enable or disable it based on your environment, to do it you only need to add the code below in your config file. + +```ruby +config.slacked_disabled = true +``` + +The default value is false + ## Contributors - [Sean H.](https://github.com/seathony)