scoped_hash 0.1.0 → 0.1.1

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: c43a499077616adecf23fe37d74b02cad241cc61
4
- data.tar.gz: 2e62d794d7ba6f0049d1653b17b0340e6d5b7127
3
+ metadata.gz: c7a980c75f3309ccf5c2886471732ce6c7a95d03
4
+ data.tar.gz: bbe2e51ab48322aeadf4f6e0b867b96216fc5ce7
5
5
  SHA512:
6
- metadata.gz: 3686545f7078d4b3aa633dd20d67a4ea1407a78006cec7905fc2f28a99dc65b1a518ee4ff1e194fc172b8e548660c008586aaf56100e1f2a85b52791b5b9aaba
7
- data.tar.gz: 9bd398d8331b750c130e9586edd097d9d86d34d3eac189847fe73bc9f4b081480eb7a75a989a8dafae0a293de11e32ffee74300792fbc39b4efa28b968d89260
6
+ metadata.gz: 732de476997991f41b6656663b75824fbaa2a73b4ac543eb92742531309cc974961b277a0431ef0ca3542522eb78069571573265eaf0bbf89f4091449aef2a41
7
+ data.tar.gz: a9873b5914194dc81d3d9249427fa10997371d56468e2eb6020f9efa3daa6b5d9c73962f22ccfe9281ccbce9c9988d6e809f1a2d67aac08a322e03ce224a9493
data/README.md CHANGED
@@ -3,14 +3,47 @@
3
3
  It provides scoped view to a hash (mash) data structure.
4
4
  When the requested scope does not exist, it would fall back to the non-scope key.
5
5
 
6
- require 'scoped_hash'
7
- smash = ScopedHash.new( 'tax': { min: 20, max: 40},
8
- 'tax(democratic)': { min: 30, max: 50},
9
- 'tax(republican)': { min: 10, max: 30})
10
-
11
- smash.scope('democratic')[:tax][:min] == 30
12
- smash.scope('republican')[:tax][:min] == 10
13
- smash.scope('green')[:tax][:min] == 20
6
+ ```ruby
7
+ require 'scoped_hash'
8
+ smash = ScopedHash.new( 'tax': { min: 20, max: 40},
9
+ 'tax(democratic)': { min: 30, max: 50},
10
+ 'tax(republican)': { min: 10, max: 30})
11
+
12
+ smash.scope('democratic')[:tax][:min] == 30
13
+ smash.scope('republican')[:tax][:min] == 10
14
+ smash.scope('green')[:tax][:min] == 20
15
+ ```
16
+
17
+ The best practice of this library is to create a YAML configuration file with scope annotation, for example the "config.yaml" could be:
18
+
19
+ ```yaml
20
+ tax:
21
+ min: 20
22
+ max: 40
23
+ max(green): 60
24
+ tax(democratic):
25
+ min: 30
26
+ max: 50
27
+ tax(republican):
28
+ min: 10
29
+ max: 30
30
+ ```
31
+
32
+ And the scoped access to the configuration could be as following:
33
+
34
+ ```ruby
35
+ require 'yaml'
36
+ require 'scoped_hash'
37
+
38
+ config = ScopedHash.new(YAML.load_file('config.yml'))
39
+
40
+ config.scope('democratic')[:tax][:min] == 30
41
+ config.scope('republican')[:tax][:min] == 10
42
+ config.scope('green')[:tax][:min] == 20
43
+
44
+ config[:tax][:max] == 40
45
+ config.scope('green')[:tax][:max] == 60
46
+ ```
14
47
 
15
48
  ## Installation
16
49
 
data/Rakefile CHANGED
@@ -13,6 +13,6 @@ task :coverage do
13
13
  end
14
14
 
15
15
  task :build do
16
- cmd="gem build smash.gemspec"
16
+ cmd="gem build scoped_hash.gemspec"
17
17
  exec cmd
18
18
  end
@@ -12,7 +12,7 @@ class ScopedHash < Mash
12
12
  end
13
13
 
14
14
  def scope(scope)
15
- mash = self.clone()
15
+ mash = Marshal.load(Marshal.dump(self))
16
16
  visit_scope(mash, scope)
17
17
  return mash
18
18
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "scoped_hash"
7
- spec.version = "0.1.0"
7
+ spec.version = "0.1.1"
8
8
  spec.authors = ["Houcheng Lin"]
9
9
  spec.email = ["houcheng@gmail.com"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoped_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Houcheng Lin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler