performify 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -2
- data/lib/performify/base.rb +0 -2
- data/lib/performify/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a683e8557fe63bce6b47dc99f35e9df354f1df02
|
4
|
+
data.tar.gz: 6ccd6d959c82eddae847f73c531e1fc8bd8f8d89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab7e975a64c0877e3e7fccb9e1fff3669288621c92d84f2007b6e34c110e672f089ba771581726ffcfcb919909e86b9b480797e0808c396b37ace33b6f8a133e
|
7
|
+
data.tar.gz: d911869f274a6e69d26f29ffd5998bad0ffe4bdbbf811f1837204768665f68d44b26b221e5d36c4fd4d7c10222997d80990d9fe3f89629e3b43e3d401fe1e417
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ How to have a deal with services:
|
|
32
32
|
4. Use `super` to work with db transaction and automatic success / fail workflow control
|
33
33
|
5. Use `success!` and `fail!` to control everything by hands
|
34
34
|
6. Use `on_success` / `on_fail` to define callbacks
|
35
|
+
7. Use `schema do ... end` if you want to use validations
|
35
36
|
|
36
37
|
### ApplicationService
|
37
38
|
|
@@ -182,7 +183,7 @@ Performify allows you to validate input arguments using [dry-validation](http://
|
|
182
183
|
|
183
184
|
```ruby
|
184
185
|
module Users
|
185
|
-
|
186
|
+
class Create
|
186
187
|
schema do
|
187
188
|
required(:email).filled(:str?)
|
188
189
|
end
|
@@ -204,7 +205,7 @@ Sometimes you can have differences between validation errors and execution error
|
|
204
205
|
|
205
206
|
```ruby
|
206
207
|
module Users
|
207
|
-
|
208
|
+
class Create
|
208
209
|
attr_reader :user
|
209
210
|
|
210
211
|
schema do
|
@@ -241,6 +242,43 @@ else
|
|
241
242
|
end
|
242
243
|
```
|
243
244
|
|
245
|
+
## Initialization
|
246
|
+
|
247
|
+
Performify will dynamically define accessors for all arguments passed to service in addition to current_user:
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
module Users
|
251
|
+
class Create
|
252
|
+
def execute!
|
253
|
+
# it will define accessors for all arguments:
|
254
|
+
User.new(email: email, role: role, manager: current_user)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
service = Users::Create.new(current_user, email: 'mail@google.com', role: 'employee')
|
260
|
+
```
|
261
|
+
|
262
|
+
But if you use `schema` to validate parameters Performify will define accessors only for additional arguments mentioned in schema:
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
module Users
|
266
|
+
class Create
|
267
|
+
schema do
|
268
|
+
required(:email).filled(:str?)
|
269
|
+
optional(:phone).filled(:str?)
|
270
|
+
end
|
271
|
+
|
272
|
+
def execute!
|
273
|
+
# it will define accessors for `email` and `phone`, but won't define `role`
|
274
|
+
User.new(email: email, phone: phone, manager: current_user) # phone is nil
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
service = Users::Create.new(current_user, email: 'mail@google.com', role: 'manager')
|
280
|
+
```
|
281
|
+
|
244
282
|
## Development
|
245
283
|
|
246
284
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/performify/base.rb
CHANGED
data/lib/performify/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: performify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Tsvetkov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|