scoped_hash 0.1.0 → 0.1.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 +4 -4
- data/README.md +41 -8
- data/Rakefile +1 -1
- data/lib/scoped_hash.rb +1 -1
- data/scoped_hash.gemspec +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: c7a980c75f3309ccf5c2886471732ce6c7a95d03
|
4
|
+
data.tar.gz: bbe2e51ab48322aeadf4f6e0b867b96216fc5ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
data/lib/scoped_hash.rb
CHANGED
data/scoped_hash.gemspec
CHANGED
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.
|
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-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|