hash_ish 0.3.0 → 0.4.0
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/.gitignore +1 -0
- data/CHANGELOG.md +13 -3
- data/README.md +15 -7
- data/hash_ish.gemspec +2 -0
- data/lib/hash_ish/add_default_values.rb +0 -7
- data/lib/hash_ish/add_instance_methods.rb +9 -1
- data/lib/hash_ish/version.rb +2 -2
- data/lib/hash_ish.rb +20 -3
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fec36fe21e88cebc85d6378d75e9ed810103eba
|
4
|
+
data.tar.gz: 330b69c6512b781d26003ae1d116d4481d1b0291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31e4ed902a3080f3d4772a4714fff4525c1deb7fe0dc656cc236c1953d6003c5cff0d736d4b348434cd243f5a2af4b1cb71d872d4a551f14dcfb9979f36f4c7d
|
7
|
+
data.tar.gz: 747e62cc355e32670a032446298bad38b934d5058fbae07a59851f8fb94fef97cf81c7b8c2939eaf47da9793a5e717d8b735ecc59c5ee9984d970d4fdd76ab0e
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.4.0 (2015-11-14)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
- No longer inherits from Hash (instead, call `.to_h` on instance)
|
5
|
+
- Add JSON support
|
6
|
+
- Values that are empty Hashes now remain a Hash
|
7
|
+
|
8
|
+
Bug fixes:
|
9
|
+
- Removed square_brackets
|
10
|
+
|
11
|
+
## 0.3.0 (2015-11-13)
|
2
12
|
|
3
13
|
Features:
|
4
14
|
- Can now add default values
|
5
15
|
- HashIsh now returns instance of self
|
6
16
|
|
7
|
-
## 0.2.0 (2015-
|
17
|
+
## 0.2.0 (2015-11-12)
|
8
18
|
|
9
19
|
Features:
|
10
|
-
- HashIsh.new now object that descends from Hash
|
20
|
+
- `HashIsh.new` now object that descends from Hash
|
data/README.md
CHANGED
@@ -24,16 +24,24 @@ bundle exec rspec
|
|
24
24
|
require 'hash_ish'
|
25
25
|
|
26
26
|
# access hash keys with method calls
|
27
|
-
hash = { a {
|
27
|
+
hash = { a: 'b', c: { d: 'e' }, f: {} }
|
28
28
|
hash_ish = HashIsh.new(hash)
|
29
|
-
hash_ish.a
|
30
|
-
hash_ish
|
31
|
-
hash_ish
|
32
|
-
hash_ish[:
|
33
|
-
hash_ish.
|
29
|
+
hash_ish.a # returns 'b'
|
30
|
+
hash_ish.a = '' # raises NoMethodError
|
31
|
+
hash_ish[:a] # returns 'b'
|
32
|
+
hash_ish[:a] = '' # raises NoMethodError
|
33
|
+
hash_ish.c # returns instance of HashIsh w/ hash of { d: 'e' }
|
34
|
+
hash_ish.c.class # returns HashIsh
|
35
|
+
hash_ish[:c] # returns { d: 'e' }
|
36
|
+
hash_ish[:c].class # returns Hash
|
37
|
+
hash_ish.c.d # returns 'e'
|
38
|
+
hash_ish.f # returns {}
|
39
|
+
hash_ish.f.class # returns Hash
|
40
|
+
hash_ish[:f] # returns {}
|
41
|
+
hash_ish[:f].class # returns Hash
|
34
42
|
|
35
43
|
# set default values
|
36
|
-
hash = { a: nil, b: { c: false }, d: { e: '
|
44
|
+
hash = { a: nil, b: { c: false }, d: { e: '>_<' } }
|
37
45
|
defaults = { a: 123, b: { c: true }, d: { e: 'ಠ_ಠ' } }
|
38
46
|
hash_ish = HashIsh.new(hash, defaults)
|
39
47
|
hash_ish.a # returns 123, overrides falsey nil
|
data/hash_ish.gemspec
CHANGED
@@ -28,10 +28,3 @@ class HashIsh
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
# puts AddDefaultValues.new.add({}, { a: 1 }).inspect
|
33
|
-
# puts AddDefaultValues.new.add({a: 2}, { a: 1 }).inspect
|
34
|
-
# puts AddDefaultValues.new.add({a: 2}, { a: 1, b: 1 }).inspect
|
35
|
-
# puts AddDefaultValues.new.add({ a: { b: nil }}, { a: { b: 1 } }).inspect
|
36
|
-
# puts AddDefaultValues.new.add({ a: { b: 2 }}, { a: { b: 1 } }).inspect
|
37
|
-
# puts AddDefaultValues.new.add({ a: { b: false }, c: { d: true }}, { a: { b: 1 }, c: { d: 123} }).inspect
|
@@ -22,8 +22,16 @@ class HashIsh
|
|
22
22
|
HashIsh.new(hash)
|
23
23
|
end
|
24
24
|
|
25
|
+
def has_keys?(value)
|
26
|
+
value.keys.size > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def should_be_a_hash_ish?(value)
|
30
|
+
is_a_hash?(value) && has_keys?(value)
|
31
|
+
end
|
32
|
+
|
25
33
|
def method_value(value)
|
26
|
-
|
34
|
+
should_be_a_hash_ish?(value) ? hash_ish(value) : value
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
data/lib/hash_ish/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class HashIsh
|
2
|
-
VERSION =
|
1
|
+
class HashIsh
|
2
|
+
VERSION = '0.4.0'
|
3
3
|
end
|
data/lib/hash_ish.rb
CHANGED
@@ -1,13 +1,30 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'hash_ish/version'
|
2
3
|
require 'hash_ish/add_default_values'
|
3
4
|
require 'hash_ish/add_instance_methods'
|
4
5
|
|
5
|
-
class HashIsh
|
6
|
+
class HashIsh
|
6
7
|
def initialize(kwargs = {}, defaults = {})
|
7
|
-
|
8
|
-
decorate_self(self,
|
8
|
+
@hash = AddDefaultValues.new.add(kwargs, defaults)
|
9
|
+
decorate_self(self, @hash)
|
9
10
|
end
|
10
11
|
|
12
|
+
def [](key)
|
13
|
+
@hash[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
@hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_json
|
21
|
+
to_hash.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
alias :to_h :to_hash
|
25
|
+
|
26
|
+
private
|
27
|
+
|
11
28
|
def decorate_self(hash_ish, kwargs)
|
12
29
|
hash_ish.tap do |hash_ish|
|
13
30
|
AddInstanceMethods.new.add(hash_ish, kwargs)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_ish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Pope
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A Hashie::Mash knockoff
|
56
70
|
email:
|
57
71
|
- mpope.cr@gmail.com
|