rails_use_case 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -2
- data/lib/rails/use_case.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9cd28e7a8c4f8f88597a7047a12e3b342a88256798572c55fbc8f30407af566
|
4
|
+
data.tar.gz: 4a2a7d0e5779aaabbf3a6a172b5f88a1cfd4faf4b6a58fab1b581c76f3d7012c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5135d55bdab90e5d8cf0c454d90712afe87726b575e49a81d9b477b204f01f05b1b7f2366542b101fa9a62742e4403e8a7846be1d6e77289ca0038bc27b60af0
|
7
|
+
data.tar.gz: c77c6b87d683be50c54e5a3c3235738e144addc3df07292954e4aca7a209ddf1bef017dfa1dc5bcb07b5bb35f2610e5d11162032aa35fa0d641717411247a58f
|
data/README.md
CHANGED
@@ -31,6 +31,9 @@ save that record or raises an exception. Also the `@record` will automatically p
|
|
31
31
|
|
32
32
|
The params should always passed as hash and are automatically assigned to instance variables.
|
33
33
|
|
34
|
+
Use Cases should be placed in the `app/use_cases/` directory and the file and class name should start with a verb like `create_blog_post.rb`.
|
35
|
+
|
36
|
+
|
34
37
|
### Example UseCase
|
35
38
|
|
36
39
|
```ruby
|
@@ -81,14 +84,55 @@ puts result.inspect
|
|
81
84
|
```
|
82
85
|
|
83
86
|
|
87
|
+
## Behavior
|
88
|
+
|
89
|
+
A behavior is simply a module that contains methods to share logic between use cases and to keep them DRY.
|
90
|
+
|
91
|
+
To use a behavior in a use case, use the `with` directive, like `with BlogPosts`.
|
92
|
+
|
93
|
+
Behaviors should be placed in the `app/behaviors/` directory and the file and module name should named in a way it can be prefixed with `with`, like `blog_posts.rb` (with blog posts).
|
94
|
+
|
95
|
+
|
96
|
+
### Example Behavior
|
97
|
+
|
98
|
+
Definition:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
module BlogPosts
|
102
|
+
def notify_subscribers
|
103
|
+
# ... send some mails ...
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
Usage:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
class CreateBlogPost < Rails::UseCase
|
112
|
+
with BlogPosts
|
113
|
+
|
114
|
+
# ...
|
115
|
+
|
116
|
+
step :build_post
|
117
|
+
step :save!
|
118
|
+
step :notify_subscribers, unless: -> { skip_notifications }
|
119
|
+
|
120
|
+
# ...
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
|
84
126
|
## Service
|
85
127
|
|
86
128
|
The purpose of a Service is to contain low level non-domain code like communication with a API,
|
87
|
-
generating an export, upload via FTP or generating a PDF. It takes params, has it's own configuration
|
88
|
-
and writes a log file.
|
129
|
+
generating an export, upload via FTP or generating a PDF. It takes params, has it's own configuration and writes a log file.
|
89
130
|
|
90
131
|
It comes with call style invocation: `PDFGenerationService.(some, params)`
|
91
132
|
|
133
|
+
Services should be placed in the `app/services/` directory and the name should end with `Service` like `PDFGenerationService` or `ReportUploadService`.
|
134
|
+
|
135
|
+
|
92
136
|
### Example Service
|
93
137
|
|
94
138
|
```ruby
|
data/lib/rails/use_case.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Klein
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|