the_help 1.0.2 → 1.1.0

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
  SHA1:
3
- metadata.gz: 11faa4a08713a7aaf31284ead2538784c24faa12
4
- data.tar.gz: a0146884e4d5b11dda20c8d82d3d390aacb6dab0
3
+ metadata.gz: '00645306911789d8f4f190c30fcbe4ec2da126de'
4
+ data.tar.gz: 895cabf435968334c1091208a3baa4d46dcdffc9
5
5
  SHA512:
6
- metadata.gz: 1b3b331eb3fda6b1c3500ff229fb2e809add4fa1c213a72705ae8e0dd4916806ea36dabba2ad86518a8e0d098b73bb4c78fee4dee9eb2ebd23706488b04cf42c
7
- data.tar.gz: 92d7fd1cdd5827bcd8fb5bcf626bf3eeb9873968256dafad8c29421d090f0a0e26df1cb5e288ff85b16b982d481791b18e9278032532cd49001d1b173242fad9
6
+ metadata.gz: c3b92751038bec65110aeed4c22c7b18de4b019d88784d05cd5287c8114132d905d94803de75ec2cf4ac812232bfa4726fc12bf8c8b7f4d7520ca769097df57c
7
+ data.tar.gz: 8a4d1f2ff9f05f8cf80d35902f2087f843b415ee27a6998ce6f7018023f57493bb90f585751705c66faedc95d3d9b8e10c91e80d192de2f2f18cd713987393dc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- the_help (1.0.2)
4
+ the_help (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -54,6 +54,7 @@ module TheHelp
54
54
  # @param name [Symbol] The name of the callback
55
55
  # @param block [Proc] The code that will be executed in the context of the
56
56
  # object when the callback is invoked.
57
+ # @return [self]
57
58
  def callback(name, &block)
58
59
  define_method("#{name}_without_logging", &block)
59
60
  define_method(name) do |*args|
@@ -61,6 +62,7 @@ module TheHelp
61
62
  logger.debug("#{inspect} received callback :#{name}.")
62
63
  end
63
64
  send("#{name}_without_logging", *args)
65
+ self
64
66
  end
65
67
  private name
66
68
  self
@@ -62,6 +62,7 @@ module TheHelp
62
62
  # CreateNewUserAccount.(context: current_user, user: new_user_object)
63
63
  class Service
64
64
  include ProvidesCallbacks
65
+ include ServiceCaller
65
66
 
66
67
  # The default :not_authorized callback
67
68
  #
@@ -73,6 +74,16 @@ module TheHelp
73
74
  }
74
75
 
75
76
  class << self
77
+ # Defines attr_accessors with scoping options
78
+ def attr_accessor(*names, make_private: false, private_reader: false,
79
+ private_writer: false)
80
+ super(*names)
81
+ names.each do |name|
82
+ private name if make_private || private_reader
83
+ private "#{name}=" if make_private || private_writer
84
+ end
85
+ end
86
+
76
87
  # Convenience method to instantiate the service and immediately call it
77
88
  #
78
89
  # Any arguments are passed to #initialize
@@ -124,7 +135,7 @@ module TheHelp
124
135
  end
125
136
 
126
137
  def input(name, **options)
127
- attr_accessor name
138
+ attr_accessor name, make_private: true
128
139
  if options.key?(:default)
129
140
  required_inputs.delete(name)
130
141
  define_method(name) do
@@ -133,7 +144,6 @@ module TheHelp
133
144
  else
134
145
  required_inputs << name
135
146
  end
136
- private name, "#{name}="
137
147
  self
138
148
  end
139
149
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TheHelp
4
+ # Provides convenience method for calling services
5
+ #
6
+ # The including module/class MUST provide the #service_context and
7
+ # #service_logger methods, which will be provided as the called-service's
8
+ # `context` and `logger` arguments, respectively.
9
+ #
10
+ # @example
11
+ # class Foo
12
+ # include TheHelp::ServiceCaller
13
+ #
14
+ # def do_something
15
+ # call_service(MyService, some: 'arguments')
16
+ # end
17
+ #
18
+ # private
19
+ #
20
+ # def service_context
21
+ # # something that provides the context
22
+ # end
23
+ #
24
+ # def service_logger
25
+ # # an instance of a `Logger`
26
+ # end
27
+ # end
28
+ module ServiceCaller
29
+ # Calls the specified service
30
+ #
31
+ # @param service [Class<TheHelp::Service>]
32
+ # @param args [Hash<Symbol, Object>] Any additional keyword arguments are
33
+ # passed directly to the service.
34
+ # @return [self]
35
+ def call_service(service, **args)
36
+ service_args = {
37
+ context: service_context,
38
+ logger: service_logger
39
+ }.merge(args)
40
+ service.call(**service_args)
41
+ self
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TheHelp
4
- VERSION = '1.0.2'
4
+ VERSION = '1.1.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: 1.0.2
4
+ version: 1.1.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: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -76,6 +76,7 @@ files:
76
76
  - lib/the_help/errors.rb
77
77
  - lib/the_help/provides_callbacks.rb
78
78
  - lib/the_help/service.rb
79
+ - lib/the_help/service_caller.rb
79
80
  - lib/the_help/version.rb
80
81
  - the_help.gemspec
81
82
  homepage: https://github.com/jwilger/the_help