the_help 3.1.0 → 3.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c3bac0cd5079035a765ff1018c38020e8f7805b00fd0e7123da0a9fe2547e15
4
- data.tar.gz: 7708a7c8c5523525b6ee909bd1395b03b898f69bb4fdab7e91b14fe6817e332c
3
+ metadata.gz: 42d6ef0b180ed2f150956e8c1bac70fde46e1f6ef221e797e79dbefc0fbb39d7
4
+ data.tar.gz: 8656a86feb9ed3054f3a48ba59441e104cfe2db9969443dfe25e1ee568946e19
5
5
  SHA512:
6
- metadata.gz: a2a35d48df57043c329f3425539ca6e8aa181bd2f9b420977c5d871caab068d1a100ad8ae2d9b924dd56022340e0c0f4c5cb4587e510955627b9db428a4c2a9b
7
- data.tar.gz: b91c4d0a6601a062987b77fbdb53760959b20332d8a071b216087568b1934ef99d5cd7e72dc19ecda5074c468e6d601154386a85f8c1e711aa69772b75e4433c
6
+ metadata.gz: d044c6844fc1a052afc36f05f255384eb6234b86b2de566a71779f48c2f5769cae6802c329a2cc3f238b3e6587b868056e5b96cb05c9d2cecc51b41a77e913ab
7
+ data.tar.gz: 7ee92bcb59848b90883e5e62d0899c2dcca9b881e7898a186ef629c841923386191d541a2850ed4a0a05bfcb2c4f87bdfd8df1c12f9cdb24bb2dd57e41739326
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- the_help (3.1.0)
4
+ the_help (3.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -150,18 +150,42 @@ module TheHelp
150
150
  self
151
151
  end
152
152
 
153
- def input(name, **options)
154
- attr_accessor name, make_private: true
155
- if options.key?(:default)
156
- required_inputs.delete(name)
157
- define_method(name) do
158
- instance_variable_get("@#{name}") || options[:default]
159
- end
153
+ # Defines a service input
154
+ #
155
+ # The specified input becomes a named parameter for the service's `#call` method.
156
+ #
157
+ # @param name [Symbol] This becomes the name of the input parameter
158
+ #
159
+ # @param block [Proc] If a block is provided, the contents of the block will be executed in
160
+ # the scope of the service instance in order to provide the default
161
+ # value of the input. This is different than providing a Proc to the
162
+ # `:default` option, which would simply return the Proc itself as the
163
+ # default value rather than calling it.
164
+ #
165
+ # @option options [Object] :default If specified (and no block is given), this becomes the
166
+ # literal default value for the input.
167
+ def input(name, **options, &block)
168
+ if options.key?(:default) || block
169
+ make_optional_input(name, options[:default], &block)
160
170
  else
171
+ attr_accessor name, make_private: true
161
172
  required_inputs << name
162
173
  end
163
174
  self
164
175
  end
176
+
177
+ private
178
+
179
+ def make_optional_input(name, default, &block)
180
+ attr_writer name
181
+ private "#{name}="
182
+ default_routine = block || -> { default }
183
+ define_method("_#{name}", &default_routine)
184
+ define_method(name) do
185
+ instance_variable_get("@#{name}") || send("_#{name}")
186
+ end
187
+ required_inputs.delete(name)
188
+ end
165
189
  end
166
190
 
167
191
  # Holds the result of running a service as well as the execution status
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TheHelp
4
- VERSION = '3.1.0'
4
+ VERSION = '3.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_help
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wilger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-01 00:00:00.000000000 Z
11
+ date: 2019-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug