service_record 1.2.2 → 1.3.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
  SHA256:
3
- metadata.gz: a7480968cffcfeaa22303ad0e8e0eefbe9eb5c748a562eb24651e1a0563fdaec
4
- data.tar.gz: cd4d145d8bf049e67586a5bc64d1b9c70939815a42996407ffd26744de2e2328
3
+ metadata.gz: 3af5f714dc3195cb0877476b9d1a7c048549cd9c19ba40ab59a30d67a3d92ff0
4
+ data.tar.gz: fc6cf02ec07809395a782754a3416bafcaf26e59c3a8af911233a69958585cf2
5
5
  SHA512:
6
- metadata.gz: e1cf4a2872060a83ac89f578721a9169db038bc4502f31a0382162ac3ea5402aa76effc3cd7f5e66c05b66a160f3148dd094fd3f9ea476d0d0902eea81a01b6e
7
- data.tar.gz: 6ea144985aa85012173f7275782e118473f22c5cc2a9a5c85c7ef8d49409f4c68b7a97de4e8fd479a9ae90e58a7e635eb594f191bafec97e29d76e7b7b2cd565
6
+ metadata.gz: ad3d7ab806691128d9790ea1f4d5e40f47b99435d0b68421b24d7c049af01783d942b2b39a9bf8357116e16d0d1bf728ce69ef73013b32dcc9630e1fe2d7ae54
7
+ data.tar.gz: 46d7eecfa6bdfcb4b323ea6f5858c19e56689c160b1ef0265c49ff9633eaf3789a27b7bce1de7b8809127502109e66b95c961ae946f4f4cfc23f132c392d229b
data/README.md CHANGED
@@ -64,7 +64,9 @@ The returned response from a service will have the following useful attributes/m
64
64
  * `success?` contains true if service was performed without any errors, false otherwise
65
65
  * `failure?` contains opposite of success?
66
66
  * `result` contains returned value of service perform function
67
- * `errors` contains details about issues that occurr while performing the service
67
+ * `errors` contains details about issues that occurr while performing the service
68
+
69
+ There is a **perform!** (with a bang !) method which will raise **ServiceRecord::Failure** in case of service failure.
68
70
 
69
71
 
70
72
 
@@ -1,7 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/named_base'
2
4
 
3
5
  module Rails
4
6
  module Generators
7
+ # Create AppicationService and SubService classes using Rails generators.
8
+ #
9
+ # E.g:
10
+ # bin/rails service my_service
11
+ #
5
12
  class ServiceGenerator < Rails::Generators::NamedBase
6
13
  desc 'This generator creates a service file at app/services'
7
14
 
@@ -1,13 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model'
1
4
  require 'service_record/failure'
2
5
  require 'service_record/callbacks'
3
6
 
4
7
  module ServiceRecord
8
+ # Base class to be extended by all service classes
9
+ #
10
+ # class MyService < ServiceRecord
11
+ # end
12
+ #
5
13
  class Base
6
14
  include Callbacks
7
15
  include ActiveModel::Attributes
8
16
  include ActiveModel::Validations
9
17
  include ActiveModel::AttributeAssignment
10
18
 
19
+ attr_accessor :result
20
+
21
+ # Wrapper around the *perform* instance method that runs all the validations
22
+ # and callbacks before eventually calling *perform*.
11
23
  def self.perform(args = {})
12
24
  new.tap do |service|
13
25
  service.attributes = args
@@ -15,27 +27,29 @@ module ServiceRecord
15
27
 
16
28
  service.run_callbacks :perform do
17
29
  service.result = service.perform
18
- service.result = nil if service.failure?
19
30
  end
20
31
  end
21
32
  end
22
33
 
34
+ # Wapper around the *perform* class method that raises exception if service fails
23
35
  def self.perform!(args = {})
24
36
  service = perform(args)
37
+ return service if service.success?
25
38
 
26
- raise Failure, service if service.failure?
39
+ raise Failure, service
27
40
  end
28
41
 
29
- attr_accessor :result
30
-
42
+ # Checks the service for errors. Returns +true+ if no errors are found, +false+ otherwise.
31
43
  def success?
32
44
  errors.empty?
33
45
  end
34
46
 
47
+ # Checks the service for errors. Returns +false+ if no errors are found, +true+ otherwise.
35
48
  def failure?
36
49
  !success?
37
50
  end
38
51
 
52
+ # Each subclass must define the *perform* method
39
53
  def perform
40
54
  raise NotImplementedError
41
55
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ServiceRecord
4
+ # Defines before/around/after callbacks for the 'perform' method
2
5
  module Callbacks
3
6
  extend ActiveSupport::Concern
4
7
 
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ServiceRecord
4
+ # Exception to be raised when a service fails
2
5
  class Failure < StandardError
3
6
  attr_reader :service
4
7
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ServiceRecord
2
- VERSION = '1.2.2'.freeze
4
+ VERSION = '1.3.0'
3
5
  end
@@ -1,2 +1,3 @@
1
- require 'active_model'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'service_record/base'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muhammad Usman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-19 00:00:00.000000000 Z
11
+ date: 2022-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -24,6 +24,156 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 13.0.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '13.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 13.0.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.9'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.9'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop-packaging
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.5.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.5.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-performance
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '1.8'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.8.1
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.8'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.8.1
109
+ - !ruby/object:Gem::Dependency
110
+ name: rubocop-rails
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '2.8'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 2.8.1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.8'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.8.1
129
+ - !ruby/object:Gem::Dependency
130
+ name: rubocop-rake
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: 0.5.1
136
+ type: :development
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: 0.5.1
143
+ - !ruby/object:Gem::Dependency
144
+ name: rubocop-rspec
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 1.44.1
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 1.44.1
160
+ - - "~>"
161
+ - !ruby/object:Gem::Version
162
+ version: '2.0'
163
+ - !ruby/object:Gem::Dependency
164
+ name: simplecov
165
+ requirement: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: 0.17.1
170
+ type: :development
171
+ prerelease: false
172
+ version_requirements: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - "~>"
175
+ - !ruby/object:Gem::Version
176
+ version: 0.17.1
27
177
  description: ActiveRecord lookalike but for business model requirements
28
178
  email:
29
179
  - uxman.sherwani@gmail.com
@@ -49,8 +199,9 @@ licenses:
49
199
  metadata:
50
200
  homepage_uri: https://github.com/uxxman/service_record
51
201
  source_code_uri: https://github.com/uxxman/service_record
202
+ rubygems_mfa_required: 'true'
52
203
  changelog_uri: https://github.com/uxxman/service_record/releases
53
- post_install_message:
204
+ post_install_message:
54
205
  rdoc_options: []
55
206
  require_paths:
56
207
  - lib
@@ -65,8 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
216
  - !ruby/object:Gem::Version
66
217
  version: '0'
67
218
  requirements: []
68
- rubygems_version: 3.1.2
69
- signing_key:
219
+ rubygems_version: 3.3.3
220
+ signing_key:
70
221
  specification_version: 4
71
222
  summary: Service objects for rails
72
223
  test_files: []