service_pattern 1.0.5 → 1.0.6

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: 6127af0c6cf5dff009118b626338c47e85cd92f920a3721b90ff17177b6d2d6f
4
- data.tar.gz: f9168398a91ef556e6aeff33f17e72b893e0d0c183d5923874b735278752ed61
3
+ metadata.gz: 96981ef35e60c1b498368709d6471d5c880538e0acf3eade1b74e533323fb502
4
+ data.tar.gz: 01b10dfe476c603e06a3a17bd5a875d2afbaf536ec4622a4ab885a5a063d5498
5
5
  SHA512:
6
- metadata.gz: 55e3cb0164fc764be393f50e5ced27f2ccf698a2459d8416148692fff790317e65af55099150550099ea8a07ccf2e8badab5980d464a832ae7c40bc647f2ec63
7
- data.tar.gz: 1f027e60f2e958df5261486e011558b0d9498765832d3f45dd7caebec6d6c1656f5b6c84da8b664ac4612aa2fa0f5c99c69b69da7b3bd72f3629c1d7e20194e3
6
+ metadata.gz: 6f7203eed9b42ee98a5cc9712be296da4983cd2aad28cd2dde4b1679cc1d41db4e3406f8f7e63f3f5b9deb2877c27c2f4d543378f552bfc011125f67ef46aefa
7
+ data.tar.gz: 6996d0eb63b2a25ad46f4ca9dad580b2acd750d9f87f98afb0e2123fd76c1e46022095a6e498d3f6867969246cb23ddbaeb93ec6b2fb27b749b335ed3bfbce7e
@@ -1,6 +1,12 @@
1
1
  class ServicePattern::Response
2
2
  attr_reader :errors, :result
3
3
 
4
+ def self.check_response!(service, response)
5
+ return if response.is_a?(ServicePattern::Response)
6
+
7
+ raise ServicePattern::InvalidResponseError, "Expected a ServicePattern::Response from #{service.class.name} but it was instead: #{response.class.name}"
8
+ end
9
+
4
10
  def initialize(errors: [], result: nil)
5
11
  @errors = ServicePattern::Service.convert_errors(errors)
6
12
  @result = result
@@ -47,7 +47,9 @@ class ServicePattern::Service
47
47
  can_execute_response = can_execute?
48
48
  return can_execute_response unless can_execute_response.success?
49
49
 
50
- perform
50
+ response = perform
51
+ ServicePattern::Response.check_response!(self, response)
52
+ response
51
53
  rescue ServicePattern::FailedError => e
52
54
  ServicePattern::Response.new(errors: e.errors)
53
55
  end
@@ -56,6 +58,7 @@ class ServicePattern::Service
56
58
  can_execute_response = can_execute?
57
59
  ServicePattern::Service.fail!(can_execute_response.errors) unless can_execute_response.success?
58
60
  response = perform
61
+ ServicePattern::Response.check_response!(self, response)
59
62
  ServicePattern::Service.fail!(response.errors) unless response.success?
60
63
  response.result
61
64
  end
@@ -1,3 +1,3 @@
1
1
  module ServicePattern
2
- VERSION = "1.0.5".freeze
2
+ VERSION = "1.0.6".freeze
3
3
  end
@@ -1,4 +1,6 @@
1
1
  module ServicePattern
2
+ class InvalidResponseError < RuntimeError; end
3
+
2
4
  path = "#{File.dirname(__FILE__)}/service_pattern"
3
5
 
4
6
  autoload :FailError, "#{path}/fail_error"
metadata CHANGED
@@ -1,15 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_pattern
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appraisal
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: best_practice_project
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 6.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 6.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: tzinfo-data
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
13
153
  description: ServicePattern for Ruby on Rails.
14
154
  email:
15
155
  - kaspernj@gmail.com