Skip to content

Commit

Permalink
Merge pull request #12 from codelittinc/feature/check_rails_config
Browse files Browse the repository at this point in the history
Feature/check rails config
  • Loading branch information
Daniel Lockhart committed Dec 8, 2015
2 parents 7f6b430 + b03c7e1 commit fa372f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,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:
Expand Down Expand Up @@ -75,6 +77,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)
Expand Down
12 changes: 11 additions & 1 deletion lib/slacked/slack_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,9 +21,19 @@ def post_async message
end
end

def disabled?
return false unless rails?
rails_config = Rails.application.config
rails_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
end

def rails?
defined?(Rails)
end
end
end
2 changes: 1 addition & 1 deletion lib/slacked/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Slacked
VERSION = "0.7.0"
VERSION = "0.9.0"
end
2 changes: 1 addition & 1 deletion slacked.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]

spec.summary = %q{A super simple and easy way to send notifications to Slack from your Rails application.}
Expand Down

0 comments on commit fa372f1

Please sign in to comment.