flowdock-rails 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +58 -20
- data/flowdock-rails.gemspec +1 -1
- data/lib/flowdock/rails/version.rb +1 -1
- data/lib/flowdock/rails.rb +32 -10
- metadata +15 -14
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Flowdock::Rails
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/flowdock-rails.svg)](http://badge.fury.io/rb/flowdock-rails)
|
4
|
+
|
3
5
|
This gem adds a class method to send notifications to specific flows for create and update events on the enabled resource
|
4
6
|
|
5
7
|
## Installation
|
@@ -20,56 +22,92 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
Just put the `notify_flow` method to your model
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
class Model < ActiveRecord::Base
|
27
|
+
notify_flow
|
28
|
+
end
|
29
|
+
```
|
26
30
|
|
27
31
|
and dont forget to set the ENV:
|
28
32
|
|
29
|
-
|
33
|
+
```
|
34
|
+
FLOWDOCK_RAILS_API_TOKEN=__FLOW_API_TOKEN__
|
35
|
+
```
|
30
36
|
|
31
37
|
You can also set the API token directly in your model:
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
```ruby
|
40
|
+
class Model < ActiveRecord::Base
|
41
|
+
notify_flow api_token: "__FLOW_API_TOKEN__"
|
42
|
+
end
|
43
|
+
```
|
36
44
|
|
37
45
|
and of course your are able to notify multiple flows:
|
38
46
|
|
39
|
-
|
40
|
-
|
41
|
-
|
47
|
+
```ruby
|
48
|
+
class Model < ActiveRecord::Base
|
49
|
+
notify_flow api_token: ["__FLOW_API_TOKEN__1", "__FLOW_API_TOKEN__2"]
|
50
|
+
end
|
51
|
+
```
|
42
52
|
|
43
53
|
or as ENV:
|
44
54
|
|
45
|
-
|
55
|
+
```
|
56
|
+
FLOWDOCK_RAILS_API_TOKEN=__FLOW_API_TOKEN__1,__FLOW_API_TOKEN__2
|
57
|
+
```
|
46
58
|
|
47
|
-
### Enabling
|
59
|
+
### Enabling and Disabling
|
48
60
|
|
49
61
|
It is enabled for production environments per default. You can enable it by setting ENV for other environments:
|
50
62
|
|
51
|
-
|
63
|
+
```
|
64
|
+
FLOWDOCK_RAILS_ENABLED=true
|
65
|
+
```
|
52
66
|
|
53
67
|
You can also explicitly disable it on production with:
|
54
68
|
|
55
|
-
|
69
|
+
```
|
70
|
+
FLOWDOCK_RAILS_ENABLED=false
|
71
|
+
```
|
56
72
|
|
57
73
|
If a global enabling/disabling mechanism is not sufficient enough for you, just override it on a per-class basis:
|
58
74
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
75
|
+
```ruby
|
76
|
+
class Model < ActiveRecord::Base
|
77
|
+
def self.push_to_flow_enabled?
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
83
|
+
#### WARNING !!!
|
84
|
+
|
85
|
+
It's force-disabled on RAILS_ENV=test by default. Currently there is no way to enable it besides overriding the class method `self.push_to_flow_enabled?`
|
86
|
+
|
87
|
+
### All ENV variables
|
88
|
+
|
89
|
+
| Variable | Description | Default |
|
90
|
+
|---|---|---|
|
91
|
+
| FLOWDOCK_RAILS_API_TOKEN | YOUR_API_TOKEN |
|
92
|
+
| FLOWDOCK_RAILS_ENABLED | Explicitly enable pushing for anything else than production.| "true" |
|
93
|
+
| FLOWDOCK_RAILS_NAME | Set the name of your project| Rails.application.class.parent_name |
|
94
|
+
| FLOWDOCK_RAILS_FROM_NAME | Name for the sender| Marv |
|
95
|
+
| FLOWDOCK_RAILS_FROM_EMAIL | Email for the sender| marv@dreimannzelt.de |
|
96
|
+
| FLOWDOCK_RAILS_FORMAT | Format of output of attributes and changes. Possible values: "table", "json" | "table" |
|
97
|
+
|
64
98
|
|
65
99
|
## TODO
|
66
100
|
|
67
101
|
1. Spec, specs, specs, specs!
|
68
102
|
2. Asynchronous and background job options
|
69
103
|
3. Option for enabling/disabling specific events (create/update)
|
70
|
-
4 Option for notification of deletion
|
104
|
+
4. Option for notification of deletion
|
71
105
|
5. Better documentation on how to override the content for the notifications
|
72
106
|
|
107
|
+
## Thanks to
|
108
|
+
|
109
|
+
* @flowdock for this amazing product
|
110
|
+
* @benedikt for the patches
|
73
111
|
|
74
112
|
## Contributing
|
75
113
|
|
data/flowdock-rails.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'flowdock/rails/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "flowdock-rails"
|
8
8
|
spec.version = Flowdock::Rails::VERSION
|
9
|
-
spec.authors = ["Björn Wolf"]
|
9
|
+
spec.authors = ["Björn Wolf", "Benedikt Deicke"]
|
10
10
|
spec.email = ["bjoern@dreimannzelt.de"]
|
11
11
|
spec.description = "Gem for notifying flows about the creation and updating of ActiveRecord models."
|
12
12
|
spec.summary = "Notify flows of model creations and updates"
|
data/lib/flowdock/rails.rb
CHANGED
@@ -13,18 +13,21 @@ module Flowdock
|
|
13
13
|
flowdock_rails_options.reverse_merge(
|
14
14
|
api_token: api_token,
|
15
15
|
source: "Flowdock Notifier",
|
16
|
-
project: ::Rails.application.class.parent_name,
|
16
|
+
project: ( ENV["FLOWDOCK_RAILS_NAME"] || ::Rails.application.class.parent_name ).parameterize,
|
17
17
|
from: {
|
18
|
-
name: "Marv",
|
19
|
-
address: "marv@dreimannzelt.de"
|
18
|
+
name: ( ENV["FLOWDOCK_RAILS_FROM_NAME"] || "Marv" ),
|
19
|
+
address: ( ENV["FLOWDOCK_RAILS_FROM_EMAIL"] || "marv@dreimannzelt.de")
|
20
20
|
}
|
21
21
|
)
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
25
|
def push_to_flow_enabled?
|
26
|
-
(
|
27
|
-
(
|
26
|
+
( !::Rails.env.test? ) &&
|
27
|
+
(
|
28
|
+
( ENV["FLOWDOCK_RAILS_ENABLED"] == "true" ) ||
|
29
|
+
( !(ENV["FLOWDOCK_RAILS_ENABLED"] == "false") && ::Rails.env.production? )
|
30
|
+
)
|
28
31
|
end
|
29
32
|
|
30
33
|
def push_to_flow(options = {})
|
@@ -51,15 +54,34 @@ module Flowdock
|
|
51
54
|
|
52
55
|
private
|
53
56
|
|
57
|
+
def formatted_attributes_for_flow(hash, changes=false)
|
58
|
+
case ENV["FLOWDOCK_RAILS_FORMAT"]
|
59
|
+
when "json"
|
60
|
+
"<pre>#{ JSON.pretty_generate(hash) }</pre>"
|
61
|
+
else
|
62
|
+
if hash.any?
|
63
|
+
%Q{
|
64
|
+
<table class="diff">
|
65
|
+
<tbody>
|
66
|
+
#{ hash.map{|k,v| "<tr><th>#{k}</th><td>#{changes ? v.first : v}</td><td>#{changes ? v.last : ""}</td></tr>" }.join("\n") }
|
67
|
+
</tbody>
|
68
|
+
</table>
|
69
|
+
}.strip
|
70
|
+
else
|
71
|
+
"<pre>Nothing to show!</pre>"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
54
76
|
def push_create_notification_to_flow
|
55
77
|
self.class.push_to_flow(
|
56
78
|
subject: "#{self.class.model_name.human} created",
|
57
79
|
content: %Q{
|
58
80
|
<h2>#{self.class.model_name.human} created</h2>
|
59
81
|
<h3>Attributes</h3>
|
60
|
-
|
82
|
+
#{formatted_attributes_for_flow self.attributes}
|
61
83
|
},
|
62
|
-
tags: [self.class.model_name.param_key, "resource", "created"]
|
84
|
+
tags: [self.class.model_name.param_key, "resource", "created", ::Rails.env]
|
63
85
|
)
|
64
86
|
end
|
65
87
|
|
@@ -69,11 +91,11 @@ module Flowdock
|
|
69
91
|
content: %Q{
|
70
92
|
<h2>#{self.class.model_name.human} updated</h2>
|
71
93
|
<h3>Changes</h3>
|
72
|
-
|
94
|
+
#{formatted_attributes_for_flow self.changes, true}
|
73
95
|
<h3>Attributes</h3>
|
74
|
-
|
96
|
+
#{formatted_attributes_for_flow self.attributes}
|
75
97
|
},
|
76
|
-
tags: [self.class.model_name.param_key, "resource", "updated"]
|
98
|
+
tags: [self.class.model_name.param_key, "resource", "updated", ::Rails.env]
|
77
99
|
)
|
78
100
|
end
|
79
101
|
end
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flowdock-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Björn Wolf
|
9
|
+
- Benedikt Deicke
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
13
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: bundler
|
16
|
-
requirement: &
|
17
|
+
requirement: &70309030445240 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ~>
|
@@ -21,10 +22,10 @@ dependencies:
|
|
21
22
|
version: '1.3'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *70309030445240
|
25
26
|
- !ruby/object:Gem::Dependency
|
26
27
|
name: rake
|
27
|
-
requirement: &
|
28
|
+
requirement: &70309030444660 !ruby/object:Gem::Requirement
|
28
29
|
none: false
|
29
30
|
requirements:
|
30
31
|
- - ! '>='
|
@@ -32,10 +33,10 @@ dependencies:
|
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
+
version_requirements: *70309030444660
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
name: flowdock
|
38
|
-
requirement: &
|
39
|
+
requirement: &70309030443940 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
42
|
- - ~>
|
@@ -43,10 +44,10 @@ dependencies:
|
|
43
44
|
version: '0.5'
|
44
45
|
type: :runtime
|
45
46
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
+
version_requirements: *70309030443940
|
47
48
|
- !ruby/object:Gem::Dependency
|
48
49
|
name: activerecord
|
49
|
-
requirement: &
|
50
|
+
requirement: &70309030443040 !ruby/object:Gem::Requirement
|
50
51
|
none: false
|
51
52
|
requirements:
|
52
53
|
- - ! '>'
|
@@ -54,10 +55,10 @@ dependencies:
|
|
54
55
|
version: '3.0'
|
55
56
|
type: :runtime
|
56
57
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
+
version_requirements: *70309030443040
|
58
59
|
- !ruby/object:Gem::Dependency
|
59
60
|
name: activesupport
|
60
|
-
requirement: &
|
61
|
+
requirement: &70309030442400 !ruby/object:Gem::Requirement
|
61
62
|
none: false
|
62
63
|
requirements:
|
63
64
|
- - ! '>'
|
@@ -65,10 +66,10 @@ dependencies:
|
|
65
66
|
version: '3.0'
|
66
67
|
type: :runtime
|
67
68
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
+
version_requirements: *70309030442400
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
71
|
name: json
|
71
|
-
requirement: &
|
72
|
+
requirement: &70309030441840 !ruby/object:Gem::Requirement
|
72
73
|
none: false
|
73
74
|
requirements:
|
74
75
|
- - ! '>='
|
@@ -76,7 +77,7 @@ dependencies:
|
|
76
77
|
version: '0'
|
77
78
|
type: :runtime
|
78
79
|
prerelease: false
|
79
|
-
version_requirements: *
|
80
|
+
version_requirements: *70309030441840
|
80
81
|
description: Gem for notifying flows about the creation and updating of ActiveRecord
|
81
82
|
models.
|
82
83
|
email:
|