var_block 1.0.3 → 1.0.4
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/lib/var_block/getvar_handlers.rb +68 -55
- data/lib/var_block/globals.rb +4 -4
- data/lib/var_block/var_array.rb +1 -0
- data/lib/var_block/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: 1558d1459d0a4c2e35d2310b99f8477f04b5b92d
|
|
4
|
+
data.tar.gz: bcc50d0ccb6d7d08f2569f428c2ba88e94c9f751
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7dd24620dd90615fb567107d70507b8e15531a45f7b7acec06951e53a05fb287f424e8b8eec5c2a86076c69ba9f6fef28bb9740495f308f4f7d078aa9d2c6738
|
|
7
|
+
data.tar.gz: b677a48857503d2201933ca60f1a9224375e6bb1eb59970534162f6d47d70ca53f2d7e6686e7d50131523e2c64f8596601319b8a6e87d14a6342267bc899054b
|
|
@@ -3,81 +3,94 @@ require 'var_block/support'
|
|
|
3
3
|
module VarBlock
|
|
4
4
|
module GetvarHandlers
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
OPTIONS = [:truthy?, :any?].freeze
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return handle_options(value, options)
|
|
15
|
-
|
|
16
|
-
# else, if no options, defaults to return as a wrapped Array
|
|
17
|
-
else
|
|
18
|
-
merged_values = []
|
|
19
|
-
|
|
20
|
-
value.each do |v|
|
|
21
|
-
if v.is_a? Proc
|
|
22
|
-
merged_values = merged_values + array_wrap(handle_proc(v, context))
|
|
23
|
-
else
|
|
24
|
-
merged_values = merged_values + array_wrap(handle_default(v))
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
return merged_values
|
|
29
|
-
end
|
|
8
|
+
module DefaultHandler
|
|
9
|
+
def self.handle(value, options = [])
|
|
10
|
+
supported_options = []
|
|
11
|
+
unsupported_options = options - supported_options
|
|
12
|
+
raise ArgumentError, "#{unsupported_options.map(&:inspect).join(', ')} option(s) are not supported on non-merged variables" if unsupported_options.any?
|
|
13
|
+
value
|
|
30
14
|
end
|
|
15
|
+
end
|
|
31
16
|
|
|
32
|
-
|
|
17
|
+
module ProcHandler
|
|
18
|
+
def self.handle(value, context, options = [])
|
|
19
|
+
supported_options = []
|
|
20
|
+
unsupported_options = options - supported_options
|
|
21
|
+
raise ArgumentError, "#{unsupported_options.map(&:inspect).join(', ')} option(s) are not supported on non-merged variables" if unsupported_options.any?
|
|
33
22
|
context.instance_exec(&value)
|
|
34
23
|
end
|
|
24
|
+
end
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
private
|
|
26
|
+
module VarArrayHandler
|
|
27
|
+
class << self
|
|
28
|
+
include VarBlock::Support
|
|
41
29
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
def handle(value, context, options)
|
|
31
|
+
if options.any?
|
|
32
|
+
return handle_options(value, options)
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
# else, if no options, defaults to return as a wrapped Array
|
|
35
|
+
else
|
|
36
|
+
merged_values = []
|
|
37
|
+
|
|
38
|
+
value.each do |v|
|
|
39
|
+
if v.is_a? Proc
|
|
40
|
+
merged_values = merged_values + array_wrap(ProcHandler.handle(v, context))
|
|
41
|
+
else
|
|
42
|
+
merged_values = merged_values + array_wrap(DefaultHandler.handle(v))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
return handle_option_any(value)
|
|
46
|
+
return merged_values
|
|
51
47
|
end
|
|
52
48
|
end
|
|
53
|
-
end
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
is_truthy = true
|
|
50
|
+
private
|
|
57
51
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
def handle_options(value, options)
|
|
53
|
+
options.each do |option|
|
|
54
|
+
case option
|
|
55
|
+
|
|
56
|
+
when :truthy?
|
|
57
|
+
return handle_option_truthy(value)
|
|
58
|
+
|
|
59
|
+
when :any?
|
|
60
|
+
return handle_option_any(value)
|
|
61
|
+
end
|
|
63
62
|
end
|
|
64
|
-
break unless is_truthy
|
|
65
63
|
end
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
def handle_option_truthy(values)
|
|
66
|
+
is_truthy = true
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
values.each do |value|
|
|
69
|
+
if value.is_a? Proc
|
|
70
|
+
evaluated_value = ProcHandler.handle(value, context)
|
|
71
|
+
else
|
|
72
|
+
evaluated_value = DefaultHandler.handle(value)
|
|
73
|
+
end
|
|
74
|
+
is_truthy = !!evaluated_value
|
|
75
|
+
break unless is_truthy
|
|
76
76
|
end
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
return is_truthy
|
|
78
79
|
end
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
def handle_option_any(values)
|
|
82
|
+
values.each do |value|
|
|
83
|
+
if value.is_a? Proc
|
|
84
|
+
evaluated_value = ProcHandler.handle(value, context)
|
|
85
|
+
else
|
|
86
|
+
evaluated_value = DefaultHandler.handle(value)
|
|
87
|
+
end
|
|
88
|
+
is_truthy = !!evaluated_value
|
|
89
|
+
return true if is_truthy
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
return false
|
|
93
|
+
end
|
|
81
94
|
end
|
|
82
95
|
end
|
|
83
96
|
end
|
data/lib/var_block/globals.rb
CHANGED
|
@@ -12,7 +12,7 @@ module VarBlock
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def getvar(var_hash, index, *options)
|
|
15
|
-
unsupported_options = (options - VarBlock::GetvarHandlers::
|
|
15
|
+
unsupported_options = (options - VarBlock::GetvarHandlers::OPTIONS)
|
|
16
16
|
raise ArgumentError, "3rd argument options Array only supports #{VarBlock::GetvarHandlers::SUPPORTED_OPTIONS}. Does not support #{unsupported_options.map(&:inspect).join(', ')}" if unsupported_options.any?
|
|
17
17
|
raise ArgumentError, "1st argument should be a VarHash object, but is found to be a #{var_hash.class}" unless var_hash.is_a? VarHash
|
|
18
18
|
raise ArgumentError, "2nd argument :#{index} is not defined. Defined are #{var_hash.keys.map(&:inspect).join(', ')}" unless var_hash.keys.include?(index)
|
|
@@ -21,11 +21,11 @@ module VarBlock
|
|
|
21
21
|
|
|
22
22
|
return_value = case value
|
|
23
23
|
when VarArray
|
|
24
|
-
VarBlock::GetvarHandlers.
|
|
24
|
+
VarBlock::GetvarHandlers::VarArrayHandler.handle(value, self, options)
|
|
25
25
|
when Proc
|
|
26
|
-
VarBlock::GetvarHandlers.
|
|
26
|
+
VarBlock::GetvarHandlers::ProcHandler.handle(value, self, options)
|
|
27
27
|
else
|
|
28
|
-
VarBlock::GetvarHandlers.
|
|
28
|
+
VarBlock::GetvarHandlers::DefaultHandler.handle(value, options)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
return_value
|
data/lib/var_block/var_array.rb
CHANGED
data/lib/var_block/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: var_block
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jules Roman B. Polidario
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-05-
|
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|