var_block 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/var_block/getvar_handlers.rb +38 -14
- data/lib/var_block/globals.rb +2 -2
- data/lib/var_block/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a6fc951b6f6f1baf1c71a9ae4ab6f7ccc08e873
|
4
|
+
data.tar.gz: 4c2eeba57f1742ae009d08f882d8ca6103851a25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa5f1b5fc5f2f7ab429f9ace3a071b98f58bc81df3a7d7f6cc1996eb59b3dc426cab368e9ecded902caaa9ff61379552de6a375f1edcdbe70a6ae504a330cfd9
|
7
|
+
data.tar.gz: d695370ead7ec3c5561c8600419959ddfb91e7e6d153b96193a9de9336c1ca017e972ca799d72d29ce1e3e02d0f2a13f5f6635db232ef709fdd64547b3a29c69
|
@@ -3,26 +3,15 @@ require 'var_block/support'
|
|
3
3
|
module VarBlock
|
4
4
|
module GetvarHandlers
|
5
5
|
|
6
|
-
SUPPORTED_OPTIONS = [:truthy?].freeze
|
6
|
+
SUPPORTED_OPTIONS = [:truthy?, :any?].freeze
|
7
7
|
|
8
8
|
class << self
|
9
9
|
include VarBlock::Support
|
10
10
|
|
11
11
|
def handle_var_array(value, context, options)
|
12
12
|
# if :truthy?, we need to check each item in the array, and return false immediately if at least one is found to be not "truthy", else return true
|
13
|
-
if options.any?
|
14
|
-
|
15
|
-
|
16
|
-
value.each do |v|
|
17
|
-
if v.is_a? Proc
|
18
|
-
is_truthy = handle_proc(v, context)
|
19
|
-
else
|
20
|
-
is_truthy = handle_default(v)
|
21
|
-
end
|
22
|
-
break unless is_truthy
|
23
|
-
end
|
24
|
-
|
25
|
-
return is_truthy
|
13
|
+
if options.any?
|
14
|
+
return handle_options(value, context, options)
|
26
15
|
|
27
16
|
# else, if no options, defaults to return as a wrapped Array
|
28
17
|
else
|
@@ -47,6 +36,41 @@ module VarBlock
|
|
47
36
|
def handle_default(value)
|
48
37
|
value
|
49
38
|
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def handle_options(value, context, options)
|
43
|
+
options.each do |option|
|
44
|
+
case option
|
45
|
+
|
46
|
+
when :truthy?
|
47
|
+
is_truthy = true
|
48
|
+
|
49
|
+
value.each do |v|
|
50
|
+
if v.is_a? Proc
|
51
|
+
is_truthy = handle_proc(v, context)
|
52
|
+
else
|
53
|
+
is_truthy = handle_default(v)
|
54
|
+
end
|
55
|
+
break unless is_truthy
|
56
|
+
end
|
57
|
+
|
58
|
+
return is_truthy
|
59
|
+
|
60
|
+
when :any?
|
61
|
+
value.each do |v|
|
62
|
+
if v.is_a? Proc
|
63
|
+
is_truthy = handle_proc(v, context)
|
64
|
+
else
|
65
|
+
is_truthy = handle_default(v)
|
66
|
+
end
|
67
|
+
return true if is_truthy
|
68
|
+
end
|
69
|
+
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
50
74
|
end
|
51
75
|
end
|
52
76
|
end
|
data/lib/var_block/globals.rb
CHANGED
@@ -31,8 +31,8 @@ module VarBlock
|
|
31
31
|
return_value
|
32
32
|
end
|
33
33
|
|
34
|
-
def with(
|
35
|
-
var_hash = VarHash.new(var_hash:
|
34
|
+
def with(var_hash_parent = nil, **variables)
|
35
|
+
var_hash = VarHash.new(var_hash: var_hash_parent)
|
36
36
|
|
37
37
|
variables.each do |key, value|
|
38
38
|
var_hash[key] = value
|
data/lib/var_block/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: var_block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jules Roman B. Polidario
|
@@ -58,9 +58,10 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '9.0'
|
61
|
-
description:
|
62
|
-
|
63
|
-
|
61
|
+
description: 'DSL for variable scoping / encapsulation for readability and organisation,
|
62
|
+
by means of block indents and explicit variable declarations. Useful when organising
|
63
|
+
complex conditions such as procs (case-in-point: complex `... if: -> {}` Rails model
|
64
|
+
validations'
|
64
65
|
email: jrpolidario@gmail.com
|
65
66
|
executables: []
|
66
67
|
extensions: []
|
@@ -96,6 +97,6 @@ rubyforge_project:
|
|
96
97
|
rubygems_version: 2.4.5.1
|
97
98
|
signing_key:
|
98
99
|
specification_version: 4
|
99
|
-
summary:
|
100
|
-
|
100
|
+
summary: DSL for variable scoping / encapsulation for readability and organisation,
|
101
|
+
by means of block indents and explicit variable declarations
|
101
102
|
test_files: []
|