simple_service 1.3.0 → 1.3.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
  SHA1:
3
- metadata.gz: c3411c81d77a21d53355ecbf0e36e8e8ab775d7f
4
- data.tar.gz: ab7e72e01db7d9f4b759f8c3a2e2b6e1a255016c
3
+ metadata.gz: d7f97f4de9f329a4f7188fb1bb5b29e05552f7fc
4
+ data.tar.gz: 4ec23950462d5ead39a0011da3bb8faa34f3c46b
5
5
  SHA512:
6
- metadata.gz: a3ec8495a52be6cd7ffa5e6e8b3a8d29e85c32011540dd4f85e2444da22ade6451a5853af1ec58ec84837a04766bfe75bbf47c74d7a9ceb1ccfb6cd1ffdb5362
7
- data.tar.gz: 6d5eb35ca7b7bb0d68f1009e0062f84cb924330887e1dafc33ca1e4e13d7f13757803a0bd583d93266530d4b8a39aa7755904b0c95b213a9655ee7526ea33608
6
+ metadata.gz: e5294419ccca5e623bd821a414cd646cd5542e741421c6ebc2168a4fc96e59da8fa3059477283e9ebe105ea009d099fb64e601a65e133e3a47d798dbe9191096
7
+ data.tar.gz: 15eeeb65864d2c0e42f4d218f4929d6ccaac2c5691049559c8a42b85a8c3e897e2e818533ac9a9c38da29f86133c0fdc75c739db27aeaa464022ce5343c67d70
@@ -0,0 +1,27 @@
1
+ module SimpleService
2
+
3
+ module Context
4
+
5
+ def success?
6
+
7
+ end
8
+
9
+ def failure?
10
+
11
+ end
12
+
13
+ def failure!
14
+
15
+ end
16
+
17
+ def update_getters_and_setters
18
+
19
+ end
20
+
21
+ def prune!(*keys)
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -40,6 +40,10 @@ module SimpleService
40
40
 
41
41
  private
42
42
 
43
+ def successful?
44
+ context[:success] == true
45
+ end
46
+
43
47
  def with_validation
44
48
  add_validation_keys_to_context unless skip_validation
45
49
 
@@ -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... allows user to implement call in
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
@@ -1,3 +1,3 @@
1
1
  module SimpleService
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -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
@@ -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.0
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-09 00:00:00.000000000 Z
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