pathway 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/lib/pathway/plugins/sequel_models.rb +18 -11
- data/lib/pathway/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: 6e5314504a8dfd84cb2f31dd46586839df19b603
|
4
|
+
data.tar.gz: c92541f944631c3b10fe3c91adaf7e31dc58a4ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eca5cc01b6a9c6705f7518add28afb922bd275f5821adcff37c9fde237fba4d29be1474ad2258e5a5849b3936e610b60ef200a5a539c32f65638861267e1d2b1
|
7
|
+
data.tar.gz: 2cd6000ff33eeb6e36a3b0fe22689d64dba3c4f91cc6916d55194e15ea1c084d8418ba38f742082d0fb47f18caf55c17d823bd2db2eae0d4c7da16ec8cfe978c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## [0.6.1] - 2018-03-16
|
2
|
+
### Changed
|
3
|
+
- Update default error message for `:fetch_model` step, at `sequel_models` plugin, to indicate the model's name
|
4
|
+
- Add `:error_message` option for `sequel_models` plugin initializer to set the default error message
|
5
|
+
- Add `:error_message` option for `:fetch_model` step to override the default error message
|
6
|
+
|
1
7
|
## [0.6.0] - 2018-03-01
|
2
8
|
### Changed
|
3
9
|
- Replace unmaintained `inflecto` gem with `dry-inflector`
|
data/README.md
CHANGED
@@ -495,7 +495,7 @@ class UpdateNugget < Pathway::Operation
|
|
495
495
|
process do
|
496
496
|
step :validate
|
497
497
|
step :fetch_model
|
498
|
-
step :fetch_model, from: User,
|
498
|
+
step :fetch_model, from: User, using: :user_id, search_by: :pk, to: :user # Even the default class can also be overrided with 'from:'
|
499
499
|
step :update_nugget
|
500
500
|
end
|
501
501
|
|
@@ -503,7 +503,7 @@ class UpdateNugget < Pathway::Operation
|
|
503
503
|
end
|
504
504
|
```
|
505
505
|
|
506
|
-
As a side note, and as
|
506
|
+
As a side note, and as shown on the 3rd step, `:fetch_model` allows you to override the search column (`search_by:`), the input parameter to extract from `input` (`using:`), the attribute to store the result (`to:`) and even the default search class (`from:`). If the current defaults doesn't fit your needs and you'll have these options available. This is commonly usefuly when you need some extra object, besides the main one, to execute your operation.
|
507
507
|
|
508
508
|
##### `transaction` and `after_commit`
|
509
509
|
|
@@ -22,12 +22,13 @@ module Pathway
|
|
22
22
|
end
|
23
23
|
|
24
24
|
module ClassMethods
|
25
|
-
attr_accessor :model_class, :search_field
|
25
|
+
attr_accessor :model_class, :search_field, :model_not_found
|
26
26
|
|
27
|
-
def model(model_class, search_by: model_class.primary_key, set_result_key: true)
|
28
|
-
self.model_class
|
29
|
-
self.search_field
|
30
|
-
self.result_key
|
27
|
+
def model(model_class, search_by: model_class.primary_key, set_result_key: true, error_message: nil)
|
28
|
+
self.model_class = model_class
|
29
|
+
self.search_field = search_by
|
30
|
+
self.result_key = Inflector.underscore(Inflector.demodulize(model_class.name)).to_sym if set_result_key
|
31
|
+
self.model_not_found = error_message || Inflector.humanize(Inflector.underscore(Inflector.demodulize(model_class.name))) + ' not found'
|
31
32
|
end
|
32
33
|
|
33
34
|
def inherited(subclass)
|
@@ -39,21 +40,27 @@ module Pathway
|
|
39
40
|
|
40
41
|
module InstanceMethods
|
41
42
|
extend Forwardable
|
42
|
-
delegate %i[model_class search_field] => 'self.class'
|
43
|
+
delegate %i[model_class search_field model_not_found] => 'self.class'
|
43
44
|
delegate :db => :model_class
|
44
45
|
|
45
|
-
def fetch_model(state, from: model_class, search_by: search_field, using: search_by, to: result_key, overwrite: false)
|
46
|
+
def fetch_model(state, from: model_class, search_by: search_field, using: search_by, to: result_key, overwrite: false, error_message: nil)
|
47
|
+
error_message ||= if from != model_class
|
48
|
+
Inflector.humanize(Inflector.underscore(Inflector.demodulize(from.name))) + ' not found'
|
49
|
+
else
|
50
|
+
model_not_found
|
51
|
+
end
|
52
|
+
|
46
53
|
if state[to].nil? || overwrite
|
47
|
-
wrap_if_present(state[:input][using])
|
48
|
-
.then { |key| find_model_with(key, from, search_by) }
|
54
|
+
wrap_if_present(state[:input][using], message: error_message)
|
55
|
+
.then { |key| find_model_with(key, from, search_by, error_message) }
|
49
56
|
.then { |model| state.update(to => model) }
|
50
57
|
else
|
51
58
|
state
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
55
|
-
def find_model_with(key, dataset = model_class, column = search_field)
|
56
|
-
wrap_if_present(dataset.first(column => key))
|
62
|
+
def find_model_with(key, dataset = model_class, column = search_field, error_message = nil)
|
63
|
+
wrap_if_present(dataset.first(column => key), message: error_message)
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|
data/lib/pathway/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Herrero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|