granite 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/granite.rb +1 -0
- data/lib/granite/action/preconditions/base_precondition.rb +1 -4
- data/lib/granite/base.rb +1 -0
- data/lib/granite/util.rb +51 -0
- data/lib/granite/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a481550ca7df8de031fb4d8c118fac213c93d5e604217a0012c33b8a9d6b38c7
|
4
|
+
data.tar.gz: 10a9a6b2edce626d410095bede6c239b8745d077389570669cd0594071f127fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f05bce79f8219eebee3a527aa1cf2ac451c9bac2d5e273123fdf599e050a6ec7000b669c78513bd00124f6b09f8305436dfdbede296b0d906ff3a5e5438151ef
|
7
|
+
data.tar.gz: daf3016428d057e31f14e140823278eb5b9150a43e805def99669269435ab48b1e97f2479d3dfda3c4f11d883e3fe08e7d1949ebdaefe7f47d56e867a6d3d08d
|
data/lib/granite.rb
CHANGED
@@ -9,10 +9,7 @@ module Granite
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def execute!(context)
|
12
|
-
|
13
|
-
return if @options[:unless] && context.instance_exec(&@options[:unless])
|
14
|
-
|
15
|
-
_execute(context)
|
12
|
+
_execute(context) if context.conditions_satisfied?(@options)
|
16
13
|
end
|
17
14
|
|
18
15
|
private
|
data/lib/granite/base.rb
CHANGED
data/lib/granite/util.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Granite
|
2
|
+
module Util
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
# Evaluates value and returns result based on what was passed:
|
6
|
+
# - if Proc was passed, then executes it in context of self
|
7
|
+
# - if Symbol was passed, then calls a method with that name and returns result
|
8
|
+
# - otherwise just returns the value itself
|
9
|
+
# @param value [Object] value to evaluate
|
10
|
+
# @return [Object] result of evaluation
|
11
|
+
def evaluate(value)
|
12
|
+
case value
|
13
|
+
when Proc
|
14
|
+
evaluate_proc(value)
|
15
|
+
when Symbol
|
16
|
+
evaluate_symbol(value)
|
17
|
+
else
|
18
|
+
value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Evaluates `if` or `unless` conditions present in the supplied
|
23
|
+
# `options` being it a symbol or callable.
|
24
|
+
#
|
25
|
+
# @param [Hash] options The method options to evaluate.
|
26
|
+
# @option options :if method name or callable
|
27
|
+
# @option options :unless method name or callable
|
28
|
+
# @return [Boolean] whether conditions are satisfied
|
29
|
+
def conditions_satisfied?(options)
|
30
|
+
fail ArgumentError, 'You cannot specify both if and unless' if options.key?(:if) && options.key?(:unless)
|
31
|
+
|
32
|
+
if options.key?(:if)
|
33
|
+
evaluate(options[:if])
|
34
|
+
elsif options.key?(:unless)
|
35
|
+
!evaluate(options[:unless])
|
36
|
+
else
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def evaluate_proc(value)
|
44
|
+
instance_exec(&value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def evaluate_symbol(value)
|
48
|
+
__send__(value)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
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.9.
|
4
|
+
version: 0.9.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkadiy Zabazhanov & friends
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -365,6 +365,7 @@ files:
|
|
365
365
|
- lib/granite/rspec/satisfy_preconditions.rb
|
366
366
|
- lib/granite/translations.rb
|
367
367
|
- lib/granite/typecasters.rb
|
368
|
+
- lib/granite/util.rb
|
368
369
|
- lib/granite/version.rb
|
369
370
|
- lib/rubocop-granite.rb
|
370
371
|
- lib/rubocop/granite.rb
|
@@ -388,7 +389,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
388
389
|
- !ruby/object:Gem::Version
|
389
390
|
version: '0'
|
390
391
|
requirements: []
|
391
|
-
rubygems_version: 3.0.
|
392
|
+
rubygems_version: 3.0.6
|
392
393
|
signing_key:
|
393
394
|
specification_version: 4
|
394
395
|
summary: Another business actions architecture for Rails apps
|