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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 670353916ff8b708f40b2e7eb3f9926fe2b732d9
4
- data.tar.gz: 9bb7c2702a1a245f54250d7b2dccdb31a5b7aea6
3
+ metadata.gz: 9a6fc951b6f6f1baf1c71a9ae4ab6f7ccc08e873
4
+ data.tar.gz: 4c2eeba57f1742ae009d08f882d8ca6103851a25
5
5
  SHA512:
6
- metadata.gz: 8cd81d7830bf189729010967b12ff753efb15bacf5fa0d224da528a49312586eef2ca834c41ce26ac3b2288d7cf6046001e9f5f0a9fc777ddb024be7f9011b79
7
- data.tar.gz: 6e0cdfbb063eb895632d8c3fc06d9f917bf98b98b5800efa6b0f2dd0f18ad9bb47e7c9d6a247c71cd963fa6d9f7cb7e6520af7c2dc29638870399fc65ee579ad
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? && options.include?(:truthy?)
14
- is_truthy = true
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
@@ -31,8 +31,8 @@ module VarBlock
31
31
  return_value
32
32
  end
33
33
 
34
- def with(var_hash = nil, **variables)
35
- var_hash = VarHash.new(var_hash: 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
@@ -1,3 +1,3 @@
1
1
  module VarBlock
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
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.8
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: Allows variable scoping / encapsulation that will be only accessible
62
- inside the given block. Useful when trying to group up logic through indents and
63
- explicit definitions.
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: Allows variable scoping / encapsulation that will be only accessible inside
100
- the given block
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: []