rails_use_case 0.0.4 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/lib/rails/callable.rb +2 -2
- data/lib/rails/service.rb +24 -5
- metadata +40 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56f84c351e857b7fd1ac1963d18138f96608376c4952fe3a12e8e7db2dbc0152
|
4
|
+
data.tar.gz: 46de14ac109e227a1a36dfdbb7f75a4e0595652c3d0e59189788cbbe8ea1ccd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 990f15747a27962ea59d7428416c8b525cf297e5e18f592fbaf3feeed8d4eecfe231bc7608acaa6516bc6273973ab651639a272c8b885f8b672fc4cb9b699ecf
|
7
|
+
data.tar.gz: '009f04d247c31452fec07815ff7be8c6af90ba3e5e03ef08f3ac4fd4b87cfcd4103cf44963ffc2a09f8791e8f9430327dd7db98f0d2e11d06feba3b646cbabd1'
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Rails Use Case gem
|
2
2
|
|
3
|
-
Opinionated gem for UseCases and Services in
|
3
|
+
Opinionated gem for UseCases and Services in Rails to keep your Models and Controllers slim.
|
4
|
+
|
5
|
+
Read more: https://dev.to/phortx/pimp-your-rails-application-32d0
|
4
6
|
|
5
7
|
The purpose of a UseCase is to contain reusable high level business logic which would normally be
|
6
8
|
located in the controller. Examples are: Place an item in the cart, create a new user or delete a comment.
|
@@ -20,7 +22,7 @@ gem 'rails_use_case'
|
|
20
22
|
|
21
23
|
The purpose of a UseCase is to contain reusable high level business logic which would normally be
|
22
24
|
located in the controller. It defines a process via `step` definitions. A UseCase takes params
|
23
|
-
and has a outcome, which is
|
25
|
+
and has a outcome, which is either successful or failed. It doesn't have a configuration file and doesn't
|
24
26
|
log anything. Examples are: Place an item in the cart, create a new user or delete a comment.
|
25
27
|
|
26
28
|
Steps are executed in the defined order. Only when a step succeeds (returns true) the next step will
|
@@ -83,6 +85,11 @@ puts result.inspect
|
|
83
85
|
# }
|
84
86
|
```
|
85
87
|
|
88
|
+
- You can check whether a UseCase was successful via `result.success?`.
|
89
|
+
- You can access the value of `@record` via `result.record`.
|
90
|
+
- You can stop the UseCase process with a error message via throwing `Rails::UseCase::Error` exception.
|
91
|
+
|
92
|
+
|
86
93
|
|
87
94
|
## Behavior
|
88
95
|
|
@@ -176,8 +183,9 @@ which is available via the `config` method.
|
|
176
183
|
|
177
184
|
### Logging
|
178
185
|
|
179
|
-
|
180
|
-
|
186
|
+
Each service automatically logs to a separate log file `log/services/[service_name].log`. You can write additional logs via `logger.info(msg)`.
|
187
|
+
|
188
|
+
It's possible to force the services to log to STDOUT by setting the environment variable `SERVICE_LOGGER_STDOUT`. This is useful for Heroku for example.
|
181
189
|
|
182
190
|
|
183
191
|
## License
|
data/lib/rails/callable.rb
CHANGED
data/lib/rails/service.rb
CHANGED
@@ -50,9 +50,28 @@ module Rails
|
|
50
50
|
|
51
51
|
# Create the log file and sets @logger
|
52
52
|
private def setup_logger
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
if ENV['SERVICE_LOGGER_STDOUT']
|
54
|
+
setup_stdout_logger
|
55
|
+
else
|
56
|
+
log_path = Rails.root.join('log', 'services')
|
57
|
+
FileUtils.mkdir_p(log_path) unless Dir.exist?(log_path)
|
58
|
+
|
59
|
+
log_file = log_path.join("#{@service_name}.log").to_s
|
60
|
+
|
61
|
+
FileUtils.touch log_file
|
62
|
+
@logger = Logger.new(log_file)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Will setup the logger for logging to STDOUT. This can be useful for
|
68
|
+
# Heroku for example.
|
69
|
+
private def setup_stdout_logger
|
70
|
+
@logger = Logger.new(STDOUT)
|
71
|
+
|
72
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
73
|
+
"[#{@service_name}] #{msg}"
|
74
|
+
end
|
56
75
|
end
|
57
76
|
|
58
77
|
|
@@ -102,8 +121,8 @@ module Rails
|
|
102
121
|
|
103
122
|
|
104
123
|
# Allows call syntax on class level: SomeService.(some, args)
|
105
|
-
def self.call(
|
106
|
-
new.(
|
124
|
+
def self.call(...)
|
125
|
+
new.(...)
|
107
126
|
end
|
108
127
|
|
109
128
|
# Allows to use rails view helpers
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_use_case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Klein
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.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:
|
26
|
+
version: 6.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 6.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 6.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler-audit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakefs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.13.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.13.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rake
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,7 +195,7 @@ homepage: https://github.com/phortx/rails-use-case
|
|
167
195
|
licenses:
|
168
196
|
- MIT
|
169
197
|
metadata: {}
|
170
|
-
post_install_message:
|
198
|
+
post_install_message:
|
171
199
|
rdoc_options: []
|
172
200
|
require_paths:
|
173
201
|
- lib
|
@@ -182,8 +210,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
210
|
- !ruby/object:Gem::Version
|
183
211
|
version: '0'
|
184
212
|
requirements: []
|
185
|
-
rubygems_version: 3.
|
186
|
-
signing_key:
|
213
|
+
rubygems_version: 3.1.2
|
214
|
+
signing_key:
|
187
215
|
specification_version: 4
|
188
216
|
summary: Rails UseCase and Service classes
|
189
217
|
test_files: []
|