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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -2
  3. data/lib/rails/use_case.rb +7 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eccdc9b039ad948018925576475a8857da769828aef5f58f2426901b6cca77c3
4
- data.tar.gz: 5ed1d23accbd83dda0428d7fc3f959366e49e5a2cb29e95ec1e641f1063d8942
3
+ metadata.gz: d9cd28e7a8c4f8f88597a7047a12e3b342a88256798572c55fbc8f30407af566
4
+ data.tar.gz: 4a2a7d0e5779aaabbf3a6a172b5f88a1cfd4faf4b6a58fab1b581c76f3d7012c
5
5
  SHA512:
6
- metadata.gz: 931eb6a75e1d92604c5f1e33140a3ddd3c20f6cbad225814f4d6e75e801e95f09d3a738d778643221f29b82f2c188c2c007e4449313297bacfee4eacd41bacd2
7
- data.tar.gz: aa4cc82f951293c672211129cdf27968bca51a218305982c55929b13ba5cafd9b60edcce5b89824b6ba4108ad0c8ec8dc3dbed6d06cc841ea04d0a4ed4b2aa1d
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
@@ -42,6 +42,13 @@ module Rails
42
42
  end
43
43
 
44
44
 
45
+ # DSL to include a behavior.
46
+ # @param mod [Module]
47
+ def self.with(mod)
48
+ include mod
49
+ end
50
+
51
+
45
52
  # Will run the steps of the use case.
46
53
  def process
47
54
  self.class.steps.each do |step|
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.3
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-02-12 00:00:00.000000000 Z
11
+ date: 2020-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties