granite 0.9.9 → 0.10.0
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/app/controllers/granite/controller/translations.rb +2 -1
- data/lib/granite/action/performing.rb +2 -2
- data/lib/granite/action/policies.rb +3 -3
- data/lib/granite/action/preconditions.rb +13 -9
- data/lib/granite/action/preconditions/base_precondition.rb +1 -1
- data/lib/granite/action/translations.rb +2 -1
- data/lib/granite/dispatcher.rb +5 -5
- data/lib/granite/projector/controller_actions.rb +2 -2
- data/lib/granite/projector/translations.rb +2 -1
- data/lib/granite/util.rb +1 -1
- data/lib/granite/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6899733124529783eda1187a978475dea09fe5c716349d50f4dbf02f0c70a90c
|
4
|
+
data.tar.gz: 81113bf6131ba438bb21af75c0b870ca3e0f8e07cbd8d754c274c259311ae640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6715806d76f01ec2f017c83bacecc3a33dc3ed9099493a2f245f84eadabe87abe5835bcfcb16fda8fc2f5b71022c84053291a1f4d4c829691cfaf216068d46
|
7
|
+
data.tar.gz: ec7f880050ff0a6b7de11d576d22038d5dcca6d0e3e71c2c7a2c4adb59280f153e05210bf7c7e4df519ddada2d5d337c12fdec34c3fddb060cf5dd82520ae3ff
|
@@ -6,7 +6,8 @@ module Granite
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def translate(*args, **options)
|
9
|
-
|
9
|
+
key, options = Granite::Translations.scope_translation_args(i18n_scopes, *args, **options)
|
10
|
+
super(key, **options)
|
10
11
|
end
|
11
12
|
|
12
13
|
alias t translate
|
@@ -42,7 +42,7 @@ module Granite
|
|
42
42
|
# @return [Object] result of execute_perform! method execution or false in case of errors
|
43
43
|
def perform(context: nil, **options)
|
44
44
|
transaction do
|
45
|
-
valid?(context) && perform_action(options)
|
45
|
+
valid?(context) && perform_action(**options)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -94,7 +94,7 @@ module Granite
|
|
94
94
|
def perform_action(raise_errors: false, **options)
|
95
95
|
result = run_callbacks(:execute_perform) do
|
96
96
|
apply_association_changes!
|
97
|
-
execute_perform!(options)
|
97
|
+
execute_perform!(**options)
|
98
98
|
end
|
99
99
|
@_action_performed = true
|
100
100
|
result || true
|
@@ -55,17 +55,17 @@ module Granite
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def try_perform!(
|
58
|
+
def try_perform!(*, **)
|
59
59
|
authorize!
|
60
60
|
super
|
61
61
|
end
|
62
62
|
|
63
|
-
def perform(
|
63
|
+
def perform(*, **)
|
64
64
|
authorize!
|
65
65
|
super
|
66
66
|
end
|
67
67
|
|
68
|
-
def perform!(
|
68
|
+
def perform!(*, **)
|
69
69
|
authorize!
|
70
70
|
super
|
71
71
|
end
|
@@ -51,15 +51,7 @@ module Granite
|
|
51
51
|
elsif args.first.is_a?(Class)
|
52
52
|
add_precondition(ObjectPrecondition, *args, options)
|
53
53
|
else
|
54
|
-
|
55
|
-
args.each do |type|
|
56
|
-
precondition common_options.merge(type => {})
|
57
|
-
end
|
58
|
-
options.each do |key, value|
|
59
|
-
value = Array.wrap(value)
|
60
|
-
precondition_options = value.extract_options!
|
61
|
-
add_precondition(klass(key), *value, precondition_options.merge!(common_options))
|
62
|
-
end
|
54
|
+
add_preconditions_hash(*args, **options)
|
63
55
|
end
|
64
56
|
end
|
65
57
|
|
@@ -72,6 +64,18 @@ module Granite
|
|
72
64
|
end || fail(NameError, "No precondition class for #{key}Precondition")
|
73
65
|
end
|
74
66
|
|
67
|
+
def add_preconditions_hash(*args, **options)
|
68
|
+
common_options = options.extract!(:if, :unless, :desc, :description)
|
69
|
+
args.each do |type|
|
70
|
+
precondition common_options.merge(type => {})
|
71
|
+
end
|
72
|
+
options.each do |key, value|
|
73
|
+
value = Array.wrap(value)
|
74
|
+
precondition_options = value.extract_options!
|
75
|
+
add_precondition(klass(key), *value, precondition_options.merge!(common_options))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
75
79
|
def add_precondition(klass, *args, &block)
|
76
80
|
self._preconditions += klass.new(*args, &block)
|
77
81
|
end
|
@@ -16,7 +16,8 @@ module Granite
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def translate(*args, **options)
|
19
|
-
|
19
|
+
key, options = Granite::Translations.scope_translation_args(self.class.i18n_scopes, *args, **options)
|
20
|
+
I18n.translate(key, **options)
|
20
21
|
end
|
21
22
|
alias t translate
|
22
23
|
end
|
data/lib/granite/dispatcher.rb
CHANGED
@@ -25,7 +25,7 @@ class Granite::Dispatcher
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def controller(params, *_args)
|
28
|
-
projector(params.
|
28
|
+
projector(*params.values_at(:granite_action, :granite_projector))&.controller_class
|
29
29
|
end
|
30
30
|
|
31
31
|
def prepare_params!(params, *_args)
|
@@ -39,19 +39,19 @@ class Granite::Dispatcher
|
|
39
39
|
controller(req.params),
|
40
40
|
action_name(
|
41
41
|
req.request_method_symbol,
|
42
|
-
req.params.
|
42
|
+
*req.params.values_at(:granite_action, :granite_projector, :projector_action)
|
43
43
|
)
|
44
44
|
]
|
45
45
|
end
|
46
46
|
|
47
|
-
memoize def action_name(request_method_symbol, granite_action
|
48
|
-
projector = projector(granite_action
|
47
|
+
memoize def action_name(request_method_symbol, granite_action, granite_projector, projector_action = '')
|
48
|
+
projector = projector(granite_action, granite_projector)
|
49
49
|
return unless projector
|
50
50
|
|
51
51
|
projector.action_for(request_method_symbol, projector_action)
|
52
52
|
end
|
53
53
|
|
54
|
-
memoize def projector(granite_action
|
54
|
+
memoize def projector(granite_action, granite_projector)
|
55
55
|
action = business_action(granite_action)
|
56
56
|
|
57
57
|
action.public_send(granite_projector) if action.respond_to?(granite_projector)
|
@@ -23,11 +23,11 @@ module Granite
|
|
23
23
|
controller_class.__send__(:define_method, name, &block)
|
24
24
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
25
25
|
def #{name}_url(options = {})
|
26
|
-
action_url(:#{name}, options.symbolize_keys)
|
26
|
+
action_url(:#{name}, **options.symbolize_keys)
|
27
27
|
end
|
28
28
|
|
29
29
|
def #{name}_path(options = {})
|
30
|
-
action_path(:#{name}, options.symbolize_keys)
|
30
|
+
action_path(:#{name}, **options.symbolize_keys)
|
31
31
|
end
|
32
32
|
METHOD
|
33
33
|
else
|
@@ -8,7 +8,8 @@ module Granite
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def translate(*args, **options)
|
11
|
-
|
11
|
+
key, options = Granite::Translations.scope_translation_args(i18n_scopes, *args, **options)
|
12
|
+
super(key, **options)
|
12
13
|
end
|
13
14
|
|
14
15
|
alias t translate
|
data/lib/granite/util.rb
CHANGED
@@ -26,7 +26,7 @@ module Granite
|
|
26
26
|
# @option options :if method name or callable
|
27
27
|
# @option options :unless method name or callable
|
28
28
|
# @return [Boolean] whether conditions are satisfied
|
29
|
-
def conditions_satisfied?(options)
|
29
|
+
def conditions_satisfied?(**options)
|
30
30
|
fail ArgumentError, 'You cannot specify both if and unless' if options.key?(:if) && options.key?(:unless)
|
31
31
|
|
32
32
|
if options.key?(:if)
|
data/lib/granite/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: granite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Toptal Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|