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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d34be83924ed7c3d112f20bc436d6554cd60796992556e5564ea5f11bd47ee8f
4
- data.tar.gz: dff8be814a80546a339d287dbf40177c812bb1e335576106bf7357e0ef335125
3
+ metadata.gz: 3edb077ec558a78e242e845f6c6f5e31466899e9261d3b25aa358ecd1ebb050f
4
+ data.tar.gz: 409913bdf7ca41cf2c0089ea95e4118a32b37b8f7c6c94d77ae6799857b6631d
5
5
  SHA512:
6
- metadata.gz: e054ed53f313c46308d07df088e16a344a8cabd68e01d9a1fccdb960e11bd8a4352081f1eb5e9309d67975d60a9cc311eb91dc310a27d6c269113490527fb270
7
- data.tar.gz: edaf7872ad85bc47a14137fc21c9724328d49158fdf41529d324f80ba122f056505ef5290b9dfde4ebbc0b1033494b4df436cf7cf6b1034c306e2087170e132c
6
+ metadata.gz: 04a66ae08e0cbcae7cf4eede6e4b482c187140669ccf7c9aff59cb65cd9dbb9602c890d14df65f6ccd5e9292d329498af9676c11bfeb9aa90569e3d3163c4942
7
+ data.tar.gz: a5846b8b1054896839eae9280a4ae9674349fe404795bc9d93f04f6d998d5e3ac9974daecdb8420615e97c5e7e05c161dc1fd164e27b67fb49697a0901e1ee1e
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ bin/*
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
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.5.2)
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
- parallel (1.12.1)
12
- parser (2.5.0.2)
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.1)
16
+ powerpack (0.1.2)
15
17
  rainbow (3.0.0)
16
18
  rake (10.5.0)
17
- rspec (3.7.0)
18
- rspec-core (~> 3.7.0)
19
- rspec-expectations (~> 3.7.0)
20
- rspec-mocks (~> 3.7.0)
21
- rspec-core (3.7.1)
22
- rspec-support (~> 3.7.0)
23
- rspec-expectations (3.7.0)
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.7.0)
26
- rspec-mocks (3.7.0)
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.7.0)
29
- rspec-support (3.7.1)
30
- rubocop (0.52.1)
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.4.0.2, < 3.0)
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.0, >= 1.0.1)
37
- ruby-progressbar (1.9.0)
38
- unicode-display_width (1.3.0)
39
- yard (0.9.12)
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.16.4
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: method(:process_widget),
44
- invalid_customer: method(:no_customer),
45
- no_widgets_found: method(:no_widgets))
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
- private
50
-
51
- def process_widget(widget)
49
+ callback(:process_widget) do |widget|
52
50
  # do something with it
53
51
  end
54
52
 
55
- def invalid_customer
53
+ callback(:invalid_customer) do
56
54
  # handle this case
57
55
  stop!
58
56
  end
59
57
 
60
- def no_widgets
58
+ callback(:no_widgets) do
61
59
  # handle this case
62
60
  end
63
61
 
64
- def do_something_else
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 `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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 https://github.com/jwilger/the_help. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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 License](https://opensource.org/licenses/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 rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jwilger/the_help/blob/master/CODE_OF_CONDUCT.md).
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
- # The provided block will be used to define an instance method. This
51
- # behaves similarly to #define_method, however it will ensure that
52
- # callbacks are logged if the object has a #logger method defined.
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
- # @param block [Proc] The code that will be executed in the context of the
56
- # object when the callback is invoked.
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
- define_method("#{name}_without_logging", &block)
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("#{name}_without_logging", *args)
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
@@ -237,8 +237,8 @@ module TheHelp
237
237
  end
238
238
 
239
239
  def log_service_call
240
- logger.info("Service call to #{self.class.name}/#{__id__} " \
241
- "for #{context.inspect}")
240
+ logger.debug("Service call to #{self.class.name}/#{__id__} " \
241
+ "for #{context.inspect}")
242
242
  end
243
243
 
244
244
  def authorized?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TheHelp
4
- VERSION = '1.5.2'
4
+ VERSION = '1.6.1'
5
5
  end
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.5.2
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: 2018-09-30 00:00:00.000000000 Z
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
- - ".ruby-version"
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.3
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