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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1a38439e44e7373d05911338c2afad7d500a620
4
- data.tar.gz: a0c37c7081ea3476a1f1303662e7df1f10f97a06
3
+ metadata.gz: 2fec36fe21e88cebc85d6378d75e9ed810103eba
4
+ data.tar.gz: 330b69c6512b781d26003ae1d116d4481d1b0291
5
5
  SHA512:
6
- metadata.gz: 0fb33597f69ca6613984817c57ebd767c2328bd5ed84145af73f941563b4790e19685c789bd11111a16572e7b5648f967f9d265f7d2976e6f7ea707fb2897400
7
- data.tar.gz: 503bae71593be3bdf69fa272a6316e8df2db40b9dcd8bf4f5666fe15a804d3163048728018b5fb465cd66576a5201159d06f064ee6d3b08b8d148ac426d32bce
6
+ metadata.gz: 31e4ed902a3080f3d4772a4714fff4525c1deb7fe0dc656cc236c1953d6003c5cff0d736d4b348434cd243f5a2af4b1cb71d872d4a551f14dcfb9979f36f4c7d
7
+ data.tar.gz: 747e62cc355e32670a032446298bad38b934d5058fbae07a59851f8fb94fef97cf81c7b8c2939eaf47da9793a5e717d8b735ecc59c5ee9984d970d4fdd76ab0e
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .DS_Store
1
2
  .gem
2
3
  /.bundle/
3
4
  /.yardoc
data/CHANGELOG.md CHANGED
@@ -1,10 +1,20 @@
1
- ## 0.3.0 (2015-07-22)
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-07-22)
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 { b: 'c' } }
27
+ hash = { a: 'b', c: { d: 'e' }, f: {} }
28
28
  hash_ish = HashIsh.new(hash)
29
- hash_ish.a.b # returns 'c', via method chaining
30
- hash_ish[:a][:b] # returns 'c', via hash square brackets
31
- hash_ish.fetch(:a) # returns { b: 'c'}, via fetch
32
- hash_ish[:d] # returns nil, just a like a Hash
33
- hash_ish.d # raises NoMethodError, doesn't return nil
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: 'lol' } }
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
@@ -22,4 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.10"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec"
25
+ spec.add_runtime_dependency 'json'
25
26
  end
27
+
@@ -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
- is_a_hash?(value) ? hash_ish(value) : value
34
+ should_be_a_hash_ish?(value) ? hash_ish(value) : value
27
35
  end
28
36
  end
29
37
  end
@@ -1,3 +1,3 @@
1
- class HashIsh < Hash
2
- VERSION = "0.3.0"
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 < Hash
6
+ class HashIsh
6
7
  def initialize(kwargs = {}, defaults = {})
7
- default_kwargs = AddDefaultValues.new.add(kwargs, defaults)
8
- decorate_self(self, default_kwargs)
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.3.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