service_record 1.2.5 → 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: 80db737dbe49a441e3251b0faeceb6db67a15753c93c78c10f9776998bc603dc
4
- data.tar.gz: 3ca3fc2e542f90c8746f7cb44051a997a2699f4bec5cf495fc92bd8d0935044b
3
+ metadata.gz: 3af5f714dc3195cb0877476b9d1a7c048549cd9c19ba40ab59a30d67a3d92ff0
4
+ data.tar.gz: fc6cf02ec07809395a782754a3416bafcaf26e59c3a8af911233a69958585cf2
5
5
  SHA512:
6
- metadata.gz: d0bacfb35fcc85561eb394015ad19da6bf87302d06feaec3bc45cea4cbade4c7b3964aa65596c401b98a6e359e0998eece7f0b3c0c543df3edd54d23cdffb67d
7
- data.tar.gz: 8b8e9f0df76338b09edf0bdef80be173af9dd01f83ddcb0be53a3f45d1df96b4963907a6253264b24e052c435284322c41879d63e7ab4813b08703476c659196
6
+ metadata.gz: ad3d7ab806691128d9790ea1f4d5e40f47b99435d0b68421b24d7c049af01783d942b2b39a9bf8357116e16d0d1bf728ce69ef73013b32dcc9630e1fe2d7ae54
7
+ data.tar.gz: 46d7eecfa6bdfcb4b323ea6f5858c19e56689c160b1ef0265c49ff9633eaf3789a27b7bce1de7b8809127502109e66b95c961ae946f4f4cfc23f132c392d229b
@@ -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,7 +1,15 @@
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
@@ -10,6 +18,8 @@ module ServiceRecord
10
18
 
11
19
  attr_accessor :result
12
20
 
21
+ # Wrapper around the *perform* instance method that runs all the validations
22
+ # and callbacks before eventually calling *perform*.
13
23
  def self.perform(args = {})
14
24
  new.tap do |service|
15
25
  service.attributes = args
@@ -21,6 +31,7 @@ module ServiceRecord
21
31
  end
22
32
  end
23
33
 
34
+ # Wapper around the *perform* class method that raises exception if service fails
24
35
  def self.perform!(args = {})
25
36
  service = perform(args)
26
37
  return service if service.success?
@@ -28,14 +39,17 @@ module ServiceRecord
28
39
  raise Failure, service
29
40
  end
30
41
 
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.5'.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.5
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-21 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
@@ -16,14 +16,164 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
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: []