the_help 1.5.2 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +0 -1
- data/.tool-versions +1 -0
- data/Gemfile.lock +26 -22
- data/README.md +24 -14
- data/lib/the_help/provides_callbacks.rb +74 -16
- data/lib/the_help/service.rb +2 -2
- data/lib/the_help/version.rb +1 -1
- data/the_help.gemspec +1 -0
- metadata +18 -4
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3edb077ec558a78e242e845f6c6f5e31466899e9261d3b25aa358ecd1ebb050f
|
4
|
+
data.tar.gz: 409913bdf7ca41cf2c0089ea95e4118a32b37b8f7c6c94d77ae6799857b6631d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04a66ae08e0cbcae7cf4eede6e4b482c187140669ccf7c9aff59cb65cd9dbb9602c890d14df65f6ccd5e9292d329498af9676c11bfeb9aa90569e3d3163c4942
|
7
|
+
data.tar.gz: a5846b8b1054896839eae9280a4ae9674349fe404795bc9d93f04f6d998d5e3ac9974daecdb8420615e97c5e7e05c161dc1fd164e27b67fb49697a0901e1ee1e
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.5.3
|
data/Gemfile.lock
CHANGED
@@ -1,47 +1,51 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
the_help (1.
|
4
|
+
the_help (1.6.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.0)
|
10
|
+
byebug (10.0.2)
|
10
11
|
diff-lcs (1.3)
|
11
|
-
|
12
|
-
|
12
|
+
jaro_winkler (1.5.2)
|
13
|
+
parallel (1.13.0)
|
14
|
+
parser (2.6.0.0)
|
13
15
|
ast (~> 2.4.0)
|
14
|
-
powerpack (0.1.
|
16
|
+
powerpack (0.1.2)
|
15
17
|
rainbow (3.0.0)
|
16
18
|
rake (10.5.0)
|
17
|
-
rspec (3.
|
18
|
-
rspec-core (~> 3.
|
19
|
-
rspec-expectations (~> 3.
|
20
|
-
rspec-mocks (~> 3.
|
21
|
-
rspec-core (3.
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-expectations (3.
|
19
|
+
rspec (3.8.0)
|
20
|
+
rspec-core (~> 3.8.0)
|
21
|
+
rspec-expectations (~> 3.8.0)
|
22
|
+
rspec-mocks (~> 3.8.0)
|
23
|
+
rspec-core (3.8.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-expectations (3.8.2)
|
24
26
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-mocks (3.8.0)
|
27
29
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-support (3.
|
30
|
-
rubocop (0.
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-support (3.8.0)
|
32
|
+
rubocop (0.63.1)
|
33
|
+
jaro_winkler (~> 1.5.1)
|
31
34
|
parallel (~> 1.10)
|
32
|
-
parser (>= 2.
|
35
|
+
parser (>= 2.5, != 2.5.1.1)
|
33
36
|
powerpack (~> 0.1)
|
34
37
|
rainbow (>= 2.2.2, < 4.0)
|
35
38
|
ruby-progressbar (~> 1.7)
|
36
|
-
unicode-display_width (~> 1.
|
37
|
-
ruby-progressbar (1.
|
38
|
-
unicode-display_width (1.
|
39
|
-
yard (0.9.
|
39
|
+
unicode-display_width (~> 1.4.0)
|
40
|
+
ruby-progressbar (1.10.0)
|
41
|
+
unicode-display_width (1.4.1)
|
42
|
+
yard (0.9.18)
|
40
43
|
|
41
44
|
PLATFORMS
|
42
45
|
ruby
|
43
46
|
|
44
47
|
DEPENDENCIES
|
48
|
+
byebug
|
45
49
|
rake (~> 10.0)
|
46
50
|
rspec (~> 3.0)
|
47
51
|
rubocop (~> 0.50)
|
@@ -49,4 +53,4 @@ DEPENDENCIES
|
|
49
53
|
yard
|
50
54
|
|
51
55
|
BUNDLED WITH
|
52
|
-
1.
|
56
|
+
1.17.1
|
data/README.md
CHANGED
@@ -40,28 +40,26 @@ class Foo < TheHelp::Service
|
|
40
40
|
main do
|
41
41
|
call_service(GetSomeWidgets,
|
42
42
|
customer_id: 12345,
|
43
|
-
each_widget:
|
44
|
-
invalid_customer:
|
45
|
-
no_widgets_found:
|
43
|
+
each_widget: callback(:process_widget),
|
44
|
+
invalid_customer: callback(:no_customer),
|
45
|
+
no_widgets_found: callback(:no_widgets))
|
46
46
|
do_something_else
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
def process_widget(widget)
|
49
|
+
callback(:process_widget) do |widget|
|
52
50
|
# do something with it
|
53
51
|
end
|
54
52
|
|
55
|
-
|
53
|
+
callback(:invalid_customer) do
|
56
54
|
# handle this case
|
57
55
|
stop!
|
58
56
|
end
|
59
57
|
|
60
|
-
|
58
|
+
callback(:no_widgets) do
|
61
59
|
# handle this case
|
62
60
|
end
|
63
61
|
|
64
|
-
|
62
|
+
callback(:do_something_else) do
|
65
63
|
# ...
|
66
64
|
end
|
67
65
|
end
|
@@ -141,21 +139,33 @@ unintended consequences further down the stack.)
|
|
141
139
|
|
142
140
|
## Development
|
143
141
|
|
144
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
142
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
143
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
144
|
+
prompt that will allow you to experiment.
|
145
145
|
|
146
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
146
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
147
|
+
release a new version, update the version number in `version.rb`, and then run
|
148
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
149
|
+
git commits and tags, and push the `.gem` file to
|
150
|
+
[rubygems.org](https://rubygems.org).
|
147
151
|
|
148
152
|
## Contributing
|
149
153
|
|
150
|
-
Bug reports and pull requests are welcome on GitHub at
|
154
|
+
Bug reports and pull requests are welcome on GitHub at
|
155
|
+
https://github.com/jwilger/the_help. This project is intended to be a safe,
|
156
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
157
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
151
158
|
|
152
159
|
## License
|
153
160
|
|
154
|
-
The gem is available as open source under the terms of the [MIT
|
161
|
+
The gem is available as open source under the terms of the [MIT
|
162
|
+
License](https://opensource.org/licenses/MIT).
|
155
163
|
|
156
164
|
## Code of Conduct
|
157
165
|
|
158
|
-
Everyone interacting in the TheHelp project’s codebases, issue trackers, chat
|
166
|
+
Everyone interacting in the TheHelp project’s codebases, issue trackers, chat
|
167
|
+
rooms and mailing lists is expected to follow the [code of
|
168
|
+
conduct](https://github.com/jwilger/the_help/blob/master/CODE_OF_CONDUCT.md).
|
159
169
|
|
160
170
|
[SRP]: https://en.wikipedia.org/wiki/Single_responsibility_principle
|
161
171
|
[TDA]: https://martinfowler.com/bliki/TellDontAsk.html
|
@@ -9,11 +9,18 @@ module TheHelp
|
|
9
9
|
#
|
10
10
|
# def do_something
|
11
11
|
# collaborator.do_some_other_thing(when_done: callback(:it_was_done))
|
12
|
+
# collaborator
|
13
|
+
# .do_some_other_thing(when_done: callback(:it_was_done_method))
|
12
14
|
# end
|
13
15
|
#
|
14
16
|
# callback(:it_was_done) do |some_arg:|
|
15
17
|
# puts "Yay! #{some_arg}"
|
16
18
|
# end
|
19
|
+
#
|
20
|
+
# def it_was_done_method(some_arg:)
|
21
|
+
# puts "In a method: #{some_arg}"
|
22
|
+
# end
|
23
|
+
# callback :it_was_done_method
|
17
24
|
# end
|
18
25
|
#
|
19
26
|
# class Bar
|
@@ -26,47 +33,98 @@ module TheHelp
|
|
26
33
|
# f.collaborator = Bar.new
|
27
34
|
# f.do_something
|
28
35
|
# # STDOUT: "Yay! done by Bar"
|
29
|
-
#
|
30
|
-
# Callbacks can be given to collaborating objects, but the actual methods are
|
31
|
-
# defined as private methods. This allows the object to control which other
|
32
|
-
# objects are able to invoke the callbacks (at least to the extent that Ruby
|
33
|
-
# lets you do so.)
|
36
|
+
# # STDOUT: "In a method: done by Bar"
|
34
37
|
#
|
35
38
|
# If the including class defines a #logger instance method, a debug-level
|
36
39
|
# message will be logged indicating that the callback was invoked.
|
37
40
|
module ProvidesCallbacks
|
41
|
+
class CallbackNotDefinedError < StandardError; end
|
42
|
+
|
38
43
|
def self.included(other)
|
39
44
|
other.class_eval do
|
40
45
|
extend TheHelp::ProvidesCallbacks::ClassMethods
|
41
|
-
alias_method :callback, :method
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
49
|
+
def callback(callback_name)
|
50
|
+
return method(callback_name) if _provides_callbacks_callback_defined?(
|
51
|
+
callback_name
|
52
|
+
)
|
53
|
+
|
54
|
+
raise CallbackNotDefinedError,
|
55
|
+
"The callback :#{callback_name} has not been defined."
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def _provides_callbacks_callback_defined?(callback_name)
|
61
|
+
self.class.send(:_provides_callbacks_callback_defined?, callback_name)
|
62
|
+
end
|
63
|
+
|
45
64
|
# Classes that include ProvidesCallbacks are extended with these
|
46
65
|
# ClassMethods
|
47
66
|
module ClassMethods
|
67
|
+
private
|
68
|
+
|
48
69
|
# Defines a callback method on the class
|
49
70
|
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
71
|
+
# Regardless of whether the callback is pointing to an existing instance
|
72
|
+
# method or if it is defined via the block argument, the callback will
|
73
|
+
# also be wrapped in logging statements that can help you trace the
|
74
|
+
# execution path through your code in the event of any anomolies.
|
53
75
|
#
|
54
|
-
# @param name [Symbol] The name of the callback
|
55
|
-
#
|
56
|
-
#
|
76
|
+
# @param name [Symbol] The name of the callback. If no block is provided,
|
77
|
+
# then name must be the name of an existing instance method.
|
78
|
+
# @param block [Proc] If a block is provided, the block will act as the
|
79
|
+
# though it is the body of an instance method when the callback is
|
80
|
+
# invoked.
|
57
81
|
# @return [self]
|
58
82
|
def callback(name, &block)
|
59
|
-
|
83
|
+
_provides_callbacks_defined_callbacks << name.to_sym
|
84
|
+
without_logging = "#{name}_without_logging".to_sym
|
85
|
+
_provides_callbacks_define_method_with_block(without_logging, &block)
|
86
|
+
_provides_callbacks_alias_method(without_logging, name)
|
87
|
+
_provides_callbacks_define_wrapper(name, without_logging)
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def _provides_callbacks_callback_defined?(name)
|
92
|
+
_provides_callbacks_defined_callbacks.include?(name.to_sym)
|
93
|
+
end
|
94
|
+
|
95
|
+
def _provides_callbacks_defined_callbacks
|
96
|
+
@_provides_callbacks_defined_callbacks ||= Set.new
|
97
|
+
end
|
98
|
+
|
99
|
+
def _provides_callbacks_method_defined?(name)
|
100
|
+
method_defined?(name) || private_method_defined?(name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def _provides_callbacks_define_method_with_block(without_logging, &block)
|
104
|
+
return unless block_given?
|
105
|
+
|
106
|
+
define_method(without_logging, &block)
|
107
|
+
private without_logging
|
108
|
+
end
|
109
|
+
|
110
|
+
def _provides_callbacks_alias_method(without_logging, name)
|
111
|
+
return unless _provides_callbacks_method_defined?(name)
|
112
|
+
|
113
|
+
alias_method without_logging, name
|
114
|
+
private without_logging
|
115
|
+
end
|
116
|
+
|
117
|
+
def _provides_callbacks_define_wrapper(name, without_logging)
|
118
|
+
make_public = public_method_defined?(name)
|
60
119
|
define_method(name) do |*args|
|
61
120
|
if defined?(logger)
|
62
121
|
logger.debug("#{self.class.name}/#{__id__} received callback " \
|
63
122
|
":#{name}.")
|
64
123
|
end
|
65
|
-
send(
|
124
|
+
send(without_logging, *args)
|
66
125
|
self
|
67
126
|
end
|
68
|
-
private name
|
69
|
-
self
|
127
|
+
private name unless make_public
|
70
128
|
end
|
71
129
|
end
|
72
130
|
end
|
data/lib/the_help/service.rb
CHANGED
@@ -237,8 +237,8 @@ module TheHelp
|
|
237
237
|
end
|
238
238
|
|
239
239
|
def log_service_call
|
240
|
-
logger.
|
241
|
-
|
240
|
+
logger.debug("Service call to #{self.class.name}/#{__id__} " \
|
241
|
+
"for #{context.inspect}")
|
242
242
|
end
|
243
243
|
|
244
244
|
def authorized?
|
data/lib/the_help/version.rb
CHANGED
data/the_help.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
+
spec.add_development_dependency 'byebug'
|
25
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
28
|
spec.add_development_dependency 'rubocop', '~> 0.50'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_help
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wilger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,7 +91,7 @@ files:
|
|
77
91
|
- ".gitignore"
|
78
92
|
- ".rspec"
|
79
93
|
- ".rubocop.yml"
|
80
|
-
- ".
|
94
|
+
- ".tool-versions"
|
81
95
|
- ".travis.yml"
|
82
96
|
- CODE_OF_CONDUCT.md
|
83
97
|
- Gemfile
|
@@ -114,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
128
|
version: '0'
|
115
129
|
requirements: []
|
116
130
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.7.
|
131
|
+
rubygems_version: 2.7.6
|
118
132
|
signing_key:
|
119
133
|
specification_version: 4
|
120
134
|
summary: A service layer framework
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.5.0
|