var_block 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b7f65d9d4b76429f4383e7ce8a339313079a411
4
+ data.tar.gz: b0c3d95ba354f2509b1813ce7b03fc94ac59e532
5
+ SHA512:
6
+ metadata.gz: 2c47f79aa0e325ed9ebc7c7640949c59ace9703e950d0223d88b391d7e51a880b1f24fc70db0467dee511804a53db75f4de66a22b0ffda9fdd649446f80ce244
7
+ data.tar.gz: d6d8c21d04898c9101ca79447bbcad99ac524ef63f7cb42efa20d3175da8424c0eba07b6b43a5a444d2e802c060296e44b6b2bec23ad20a46ec6abb0af37da8a
@@ -0,0 +1,25 @@
1
+ module VarBlock
2
+ module Globals
3
+ def self.included(base)
4
+ # fail if there is already same-name methods to prevent breaking dependencies
5
+ overrides = instance_methods.select { |method| base.instance_method(method).owner != self }
6
+ raise "#{self.name} overrides #{overrides.join(', ')}" if overrides.any?
7
+
8
+ base.extend self
9
+ end
10
+
11
+ def getvar(triggered_variables, index)
12
+ instance_exec &triggered_variables[index]
13
+ end
14
+
15
+ def with(variables, var_hash: nil)
16
+ var_hash = VarHash.new(var_hash: var_hash)
17
+
18
+ variables.each do |key, value|
19
+ var_hash[key] = value
20
+ end
21
+
22
+ yield var_hash
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module VarBlock
2
+ class VarHash < Hash
3
+ include Globals
4
+
5
+ def initialize(var_hash: nil)
6
+ if var_hash
7
+ raise ArgumentError.new('`instance` should be a `VarHash` object') unless var_hash.is_a? VarHash
8
+ self.merge!(var_hash)
9
+ end
10
+ self
11
+ end
12
+
13
+ def with(variables)
14
+ super(variables, var_hash: self)
15
+ end
16
+ end
17
+ end
data/lib/var_block.rb ADDED
@@ -0,0 +1,8 @@
1
+ files = Dir[__dir__ + '/var_block/*.rb'].each {|file| require file }
2
+
3
+ module VarBlock
4
+ end
5
+
6
+ class Object
7
+ include VarBlock::Globals
8
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: var_block
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jules Roman B. Polidario
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows variable scoping / encapsulation that will be only accessible
14
+ inside the given block. Useful when trying to group up logic through indents.
15
+ email: 'jrpolidario@gmail.com '
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/var_block.rb
21
+ - lib/var_block/globals.rb
22
+ - lib/var_block/var_hash.rb
23
+ homepage: http://rubygems.org/gems/var_block
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.5.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Allows variable scoping / encapsulation that will be only accessible inside
47
+ the given block
48
+ test_files: []