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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a96ab69ab79f8f0b99f818b762c932b86d31ecc6
4
- data.tar.gz: 58b169f4eccdffbb8caf2fddee1c5b89bb4369d4
3
+ metadata.gz: a683e8557fe63bce6b47dc99f35e9df354f1df02
4
+ data.tar.gz: 6ccd6d959c82eddae847f73c531e1fc8bd8f8d89
5
5
  SHA512:
6
- metadata.gz: 1a1e944109d8ad0205d7080234a9073031f98af811c6b90aa018564661fd435c75952393c580e10a1881996eef203bbec337e38105199f4e3f1934162a3b2c3a
7
- data.tar.gz: 82897b5b49b010f89481da7c23dda87f200b22f2e0ad7d63719aeb87ba99584cc10f92f5b697c51595eac21a074a5f4d050e793cab584ba6b065f45a6778b00a
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
- module Create
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
- module Create
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.
@@ -16,8 +16,6 @@ module Performify
16
16
  super(&block)
17
17
  end
18
18
 
19
- return if args.empty?
20
-
21
19
  validate(args)
22
20
  define_singleton_methods(args)
23
21
 
@@ -1,3 +1,3 @@
1
1
  module Performify
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
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.0
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-12 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord