simple_service 1.3.0 → 1.3.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/lib/simple_service/context.rb +27 -0
- data/lib/simple_service/organizer.rb +4 -0
- data/lib/simple_service/service_base.rb +16 -3
- data/lib/simple_service/version.rb +1 -1
- data/spec/lib/command_spec.rb +8 -0
- data/spec/lib/organizer_spec.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7f97f4de9f329a4f7188fb1bb5b29e05552f7fc
|
4
|
+
data.tar.gz: 4ec23950462d5ead39a0011da3bb8faa34f3c46b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5294419ccca5e623bd821a414cd646cd5542e741421c6ebc2168a4fc96e59da8fa3059477283e9ebe105ea009d099fb64e601a65e133e3a47d798dbe9191096
|
7
|
+
data.tar.gz: 15eeeb65864d2c0e42f4d218f4929d6ccaac2c5691049559c8a42b85a8c3e897e2e818533ac9a9c38da29f86133c0fdc75c739db27aeaa464022ce5343c67d70
|
@@ -13,10 +13,24 @@ module SimpleService
|
|
13
13
|
def skip_validation(skip=true)
|
14
14
|
@skip_validation = skip
|
15
15
|
end
|
16
|
+
|
17
|
+
# allow execution of the service or commands from the
|
18
|
+
# class level for those that prefer that style
|
19
|
+
def call(context = {})
|
20
|
+
new(context).call
|
21
|
+
end
|
22
|
+
|
16
23
|
end
|
17
24
|
|
18
25
|
module InstanceMethods
|
19
26
|
|
27
|
+
# sets up an "after" filter for #call
|
28
|
+
#
|
29
|
+
# allows user to implement #call in their individual
|
30
|
+
# command and organizer # classes without having to
|
31
|
+
# rely on super or executing another other method
|
32
|
+
# to do post #call housekeeping such as returning
|
33
|
+
# only specific context keys
|
20
34
|
def setup_call_chain
|
21
35
|
self.class.class_eval do
|
22
36
|
|
@@ -24,9 +38,7 @@ module SimpleService
|
|
24
38
|
call_method = instance_method(:call)
|
25
39
|
|
26
40
|
# redefine the call method, execute the existing call method object,
|
27
|
-
# and then run return key checking...
|
28
|
-
# their individual command classes without having to call super or any
|
29
|
-
# other method to return only specific context keys
|
41
|
+
# and then run return key checking...
|
30
42
|
define_method :call do
|
31
43
|
call_method.bind(self).call
|
32
44
|
return_context_with_success_status
|
@@ -44,6 +56,7 @@ module SimpleService
|
|
44
56
|
_context = find_specified_return_keys
|
45
57
|
|
46
58
|
# only automatically set context[:success] on Organizers and only if its not already set
|
59
|
+
# by a command calling #failure!
|
47
60
|
if !_context.has_key?(:success) && self.class.ancestors.include?(SimpleService::Organizer)
|
48
61
|
_context[:success] = true
|
49
62
|
end
|
data/spec/lib/command_spec.rb
CHANGED
@@ -23,6 +23,14 @@ describe SimpleService::Command do
|
|
23
23
|
class CallNotDefinedCommand < SimpleService::Command
|
24
24
|
end
|
25
25
|
|
26
|
+
describe '.call' do
|
27
|
+
it 'returns the correct keys when using class method' do
|
28
|
+
expect(
|
29
|
+
ValidCommand.call(foo: 'blah', bar: 'meh')
|
30
|
+
).to eql(bar: 'modified', baz: 'blah')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
26
34
|
describe '#call' do
|
27
35
|
|
28
36
|
context 'when #returns is not empty' do
|
data/spec/lib/organizer_spec.rb
CHANGED
@@ -26,6 +26,14 @@ describe SimpleService::Organizer do
|
|
26
26
|
commands TestCommandOne, TestCommandTwo
|
27
27
|
end
|
28
28
|
|
29
|
+
describe '.call' do
|
30
|
+
it 'returns the correct hash' do
|
31
|
+
expect(
|
32
|
+
TestOrganizer.call(foo: 'foo')
|
33
|
+
).to eql(foo: 'foo', bar: 'bar', baz: 'baz', success: true)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
describe '#call' do
|
30
38
|
it 'returns the correct hash' do
|
31
39
|
expect(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarrod Spillers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/simple_service/commands/validates_commands_not_empty.rb
|
106
106
|
- lib/simple_service/commands/validates_commands_properly_inherit.rb
|
107
107
|
- lib/simple_service/commands/validates_expected_keys.rb
|
108
|
+
- lib/simple_service/context.rb
|
108
109
|
- lib/simple_service/ensure_organizer_is_valid.rb
|
109
110
|
- lib/simple_service/exceptions.rb
|
110
111
|
- lib/simple_service/organizer.rb
|