aha 1.0.0 → 1.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 +4 -4
- data/README.md +69 -13
- data/lib/aha/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fee7461ca33670cd06d3e0ba15144dbe5c70302e
|
4
|
+
data.tar.gz: 1f1679c8cf4aac1aca799c7fa80fbe4f1317e6c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b28862c8eae277802caee38c1a3ad48ffebb66f77e7382cccac910153c5c24ef02e7df49fc01d3e8e45fc5c6386d150c4b1c048e4d8ca01bb4726504361d76ca
|
7
|
+
data.tar.gz: 46958e1b06abd0a6dffe2f5f6bb9934e3c10222c68a31e892cb3390e4bf1671c93d9bf3afa5ac5e4b81a9a5f9b26be431c6db7e80440b2ef11d02803bed8341a
|
data/README.md
CHANGED
@@ -1,31 +1,87 @@
|
|
1
1
|
# Aha
|
2
2
|
|
3
|
-
|
3
|
+
A(ugmented)ha(sh) is a Hash extension library that makes it easy to work with
|
4
|
+
data represented by nested hash maps.
|
5
|
+
|
6
|
+
It was largely inspired by Uncle Bob's [keynote](http://www.confreaks.com/videos/759-rubymidwest2011-keynote-architecture-the-lost-years)
|
7
|
+
'Architecture: the lost years' and the insight that while domain modeling with
|
8
|
+
objects is great, we want to deal with plain data structures at the boundaries
|
9
|
+
of our system.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
7
|
-
|
13
|
+
```shell
|
14
|
+
gem install aha
|
15
|
+
```
|
16
|
+
or add the following line to your application's Gemfile:
|
8
17
|
|
9
18
|
```ruby
|
10
19
|
gem 'aha'
|
11
20
|
```
|
21
|
+
and run `bundle install` from your shell.
|
22
|
+
|
23
|
+
## Usage
|
12
24
|
|
13
|
-
|
25
|
+
```ruby
|
26
|
+
# some data to play with
|
27
|
+
def data
|
28
|
+
{:a => 'value_1',
|
29
|
+
'b' => {:c => 'value_2',
|
30
|
+
:d => 'value_3'},
|
31
|
+
:e => {:f => 'value_4',
|
32
|
+
:g => {:h => 'value_5'}}}
|
33
|
+
end
|
14
34
|
|
15
|
-
|
35
|
+
# Destructuring assignment
|
36
|
+
value_1, value_2, value_3, value_4, value_5
|
37
|
+
= data.vals_at :a, ['b', :c, :d], [:e, :f [:g, :h]]
|
16
38
|
|
17
|
-
|
39
|
+
# Get nested values from top level object
|
40
|
+
data.get_in :e, :g, :h
|
41
|
+
# => 'value_5'
|
18
42
|
|
19
|
-
|
43
|
+
# Set nested values from top level object
|
44
|
+
d1 = data
|
45
|
+
d1.put_in! :e, :g, :h, 'new_value'
|
46
|
+
d1.get_in :e, :g, :h
|
47
|
+
# => 'new_value'
|
20
48
|
|
21
|
-
|
49
|
+
# Update nested values from top level object
|
50
|
+
d2 = data
|
51
|
+
d2.update_in!(:e, :g, :h) { |v| v * 3 }
|
52
|
+
d2.get_in :e, :g, :h
|
53
|
+
# => 'value_5value_5value_5'
|
54
|
+
|
55
|
+
# Delete nested values from top level object
|
56
|
+
d3 = data
|
57
|
+
d3.delete_in! 'b', :d
|
58
|
+
d3['b']
|
59
|
+
# => {:c => 'value_2'}
|
60
|
+
|
61
|
+
# Exclude keys from nested hash
|
62
|
+
d4 = data
|
63
|
+
d4.exclude! :a, ['b', :c], [:e, :g]
|
64
|
+
d4
|
65
|
+
# => {'b' => {:d => 'value_3'}, :e => {:f => 'value_4'}}
|
22
66
|
|
23
|
-
|
67
|
+
# Keep a subset of keys
|
68
|
+
d5 = data
|
69
|
+
d5.only :a, [:e, [:g, :h]]
|
70
|
+
# => {:a => 'value_1', :e => {:g => {:h => 'value_5'}}}
|
71
|
+
|
72
|
+
```
|
73
|
+
|
74
|
+
## Planned
|
75
|
+
|
76
|
+
* Non-destructive variants of all the existing methods
|
24
77
|
|
25
78
|
## Contributing
|
26
79
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
80
|
+
* If it is a new feature please create an issue first.
|
81
|
+
* Fork and send me a pull request. Tests are a must!
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
Copyright © 2014 Mike Jackson.
|
86
|
+
|
87
|
+
Distributed under the permissive [MIT license](http://opensource.org/licenses/MIT).
|
data/lib/aha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Jackson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,7 @@ files:
|
|
94
94
|
- lib/aha/version.rb
|
95
95
|
- spec/lib/aha_spec.rb
|
96
96
|
- spec/spec_helper.rb
|
97
|
-
homepage: https://
|
97
|
+
homepage: https://github.com/occamin/aha
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
metadata: {}
|