junk_drawer 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Guardfile +1 -0
- data/README.md +48 -1
- data/Rakefile +1 -0
- data/junk_drawer.gemspec +1 -0
- data/lib/junk_drawer.rb +4 -0
- data/lib/junk_drawer/callable.rb +1 -0
- data/lib/junk_drawer/notifier.rb +36 -0
- data/lib/junk_drawer/notifier/honeybadger_strategy.rb +19 -0
- data/lib/junk_drawer/notifier/null_strategy.rb +16 -0
- data/lib/junk_drawer/notifier/raise_strategy.rb +18 -0
- data/lib/junk_drawer/version.rb +2 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f11e6f56418b14bf2a44d91ffadff154fcf79a6
|
4
|
+
data.tar.gz: 2240a549479b367d864b343fc3d5106821fa074c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1692ef49d130c6b5e761fe1587871cbc3ebced928965eb98464dfc88ec0e436fa80de0837f4fa87162f2d162c3aba70cd571e72d3844380a5c1811a0bbadb7e
|
7
|
+
data.tar.gz: baaa55a6d653c4f514b0850777e31616f93af87758bfb592f629240934e7f7675eb5fa03780e8933618bc9140f8a399bf969138b1ce0ce391ac8bf28100effdd
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,9 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
`JunkDrawer::Callable` is a module that provides constraints and conveniences
|
27
27
|
for objects that implement a single method `#call`. It comes with the
|
28
|
-
philosophy that objects that *do* something, should do only one thing. When
|
28
|
+
philosophy that objects that *do* something, should do only one thing. When
|
29
|
+
including the `JunkDrawer::Callable` in one of your classes, you will get the
|
30
|
+
following:
|
29
31
|
|
30
32
|
1) It raises an error if you try to implement a public method other than
|
31
33
|
`#call`.
|
@@ -87,6 +89,51 @@ philosophy that objects that *do* something, should do only one thing. When incl
|
|
87
89
|
|
88
90
|
http://www.brianstorti.com/understanding-ruby-idiom-map-with-symbol/
|
89
91
|
|
92
|
+
-------------------------------------------------------------------------------
|
93
|
+
|
94
|
+
### JunkDrawer::Notifier
|
95
|
+
|
96
|
+
`JunkDrawer::Notifier` is a class that provides simple notification strategies
|
97
|
+
for different environments. When you call it, it will send a notification via
|
98
|
+
your selected strategy. The strategies available are as follows:
|
99
|
+
|
100
|
+
1) `:raise` raises an error when you call the notifier:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
JunkDrawer::Notifier.strategy = :raise
|
104
|
+
JunkDrawer::Notifier.call('some message', some: 'context')
|
105
|
+
```
|
106
|
+
|
107
|
+
produces:
|
108
|
+
|
109
|
+
```
|
110
|
+
JunkDrawer::NotifierError: some message, context: {:some=>"context"}
|
111
|
+
```
|
112
|
+
|
113
|
+
2) `:honeybadger` will send a notification to Honeybadger. You'll need to make
|
114
|
+
sure you have Honeybadger required in your application and configured for
|
115
|
+
this to work.
|
116
|
+
|
117
|
+
3) `:null` is a noop. If you want to disable notifications temporarily, you can
|
118
|
+
configure the strategy to `:null`.
|
119
|
+
|
120
|
+
If you're using Rails, you may want to configure `Notifier` based on the
|
121
|
+
environment, so in your `config/environments/development.rb` you might have:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
config.after_initialize do
|
125
|
+
JunkDrawer::Notifier.strategy = :raise
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
While in `production.rb` you might want:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
config.after_initialize do
|
133
|
+
JunkDrawer::Notifier.strategy = :honeybadger
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
90
137
|
## Development
|
91
138
|
|
92
139
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/Rakefile
CHANGED
data/junk_drawer.gemspec
CHANGED
data/lib/junk_drawer.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require_relative 'junk_drawer/callable'
|
4
|
+
require_relative 'junk_drawer/notifier'
|
3
5
|
require_relative 'junk_drawer/version'
|
4
6
|
|
5
7
|
# namespace for all JunkDrawer code
|
6
8
|
module JunkDrawer
|
9
|
+
class NotifierError < StandardError
|
10
|
+
end
|
7
11
|
end
|
data/lib/junk_drawer/callable.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'notifier/honeybadger_strategy'
|
4
|
+
require_relative 'notifier/null_strategy'
|
5
|
+
require_relative 'notifier/raise_strategy'
|
6
|
+
|
7
|
+
module JunkDrawer
|
8
|
+
# class to send dev notifications to different channels
|
9
|
+
class Notifier
|
10
|
+
|
11
|
+
include Callable
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
attr_accessor :strategy
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
STRATEGIES = {
|
20
|
+
honeybadger: HoneybadgerStrategy,
|
21
|
+
raise: RaiseStrategy,
|
22
|
+
null: NullStrategy,
|
23
|
+
}.freeze
|
24
|
+
|
25
|
+
def call(*args)
|
26
|
+
strategy.(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def strategy
|
32
|
+
STRATEGIES.fetch(self.class.strategy)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JunkDrawer
|
4
|
+
class Notifier
|
5
|
+
|
6
|
+
# Notifier strategy to send a notification to Honeybadger
|
7
|
+
class HoneybadgerStrategy
|
8
|
+
|
9
|
+
include Callable
|
10
|
+
|
11
|
+
def call(message, **context)
|
12
|
+
error = message.is_a?(Exception) ? message : NotifierError.new(message)
|
13
|
+
Honeybadger.notify(error, context: context)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JunkDrawer
|
4
|
+
class Notifier
|
5
|
+
|
6
|
+
# Notifier strategy to raise an error when notification is triggered
|
7
|
+
class RaiseStrategy
|
8
|
+
|
9
|
+
include Callable
|
10
|
+
|
11
|
+
def call(message, **context)
|
12
|
+
raise NotifierError, "#{message}, context: #{context}"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/junk_drawer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: junk_drawer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Fletcher
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,6 +172,10 @@ files:
|
|
172
172
|
- junk_drawer.gemspec
|
173
173
|
- lib/junk_drawer.rb
|
174
174
|
- lib/junk_drawer/callable.rb
|
175
|
+
- lib/junk_drawer/notifier.rb
|
176
|
+
- lib/junk_drawer/notifier/honeybadger_strategy.rb
|
177
|
+
- lib/junk_drawer/notifier/null_strategy.rb
|
178
|
+
- lib/junk_drawer/notifier/raise_strategy.rb
|
175
179
|
- lib/junk_drawer/version.rb
|
176
180
|
homepage: https://github.com/mockdeep/junk_drawer
|
177
181
|
licenses:
|
@@ -193,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
197
|
version: '0'
|
194
198
|
requirements: []
|
195
199
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.6.
|
200
|
+
rubygems_version: 2.6.11
|
197
201
|
signing_key:
|
198
202
|
specification_version: 4
|
199
203
|
summary: random useful Ruby utilities
|