hashugar 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hashugar.rb +14 -3
- data/lib/hashugar/version.rb +1 -1
- data/spec/hashugar_spec.rb +27 -1
- metadata +18 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2bb945298216410af1aa89a8429ddfb5f3136a3b
|
4
|
+
data.tar.gz: 465bd7d004c301c0dcd0a948bf4827134675bc3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 05f221a525337383dc8f7ce7c17e880f427e38a2a9d00b6955689b13f49a762fe46b09dc49d8bade968336d31a5d13bffd7def183bed3d6839886a1f9f4fe57f
|
7
|
+
data.tar.gz: c7bb5ba2cb8c4df63fda7c9cea5b99245df474c2ef32cee583f366d3ff9998800f86fa0bd3739238a34434ec698c0f1192b143a2637acd36749d062d5357c56d
|
data/lib/hashugar.rb
CHANGED
@@ -28,14 +28,25 @@ class Hashugar
|
|
28
28
|
@table[stringify(key)] = value
|
29
29
|
end
|
30
30
|
|
31
|
-
def respond_to?(key)
|
32
|
-
@table.has_key?(stringify(key))
|
31
|
+
def respond_to?(key, include_all=false)
|
32
|
+
super(key) || @table.has_key?(stringify(key))
|
33
33
|
end
|
34
34
|
|
35
35
|
def each(&block)
|
36
36
|
@table_with_original_keys.each(&block)
|
37
37
|
end
|
38
38
|
|
39
|
+
def to_hash
|
40
|
+
hash = @table_with_original_keys.to_hash
|
41
|
+
hash.each do |key, value|
|
42
|
+
hash[key] = value.to_hash if value.is_a?(Hashugar)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def empty?
|
47
|
+
@table.empty?
|
48
|
+
end
|
49
|
+
|
39
50
|
private
|
40
51
|
def stringify(key)
|
41
52
|
key.is_a?(Symbol) ? key.to_s : key
|
@@ -58,4 +69,4 @@ class Object
|
|
58
69
|
def to_hashugar
|
59
70
|
self
|
60
71
|
end
|
61
|
-
end
|
72
|
+
end
|
data/lib/hashugar/version.rb
CHANGED
data/spec/hashugar_spec.rb
CHANGED
@@ -89,4 +89,30 @@ describe Hashugar do
|
|
89
89
|
expect(values).to eq([4, 2])
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
|
+
describe '#to_hash' do
|
94
|
+
it 'responds to to_hash' do
|
95
|
+
expect(Hashugar.new({}).respond_to?(:to_hash)).to be true
|
96
|
+
end
|
97
|
+
it 'returns the original hash' do
|
98
|
+
hashugar = Hashugar.new({:a => 4, :c => 2})
|
99
|
+
expect(hashugar.to_hash).to eq({:a => 4, :c => 2})
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when containing nested hashugar' do
|
103
|
+
it 'returns the original hash' do
|
104
|
+
hashugar = Hashugar.new({ nested: { a: 4, c: 2 } })
|
105
|
+
expect(hashugar.to_hash[:nested]).to eq({:a => 4, :c => 2})
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#empty?' do
|
111
|
+
it 'behaves like the original hash' do
|
112
|
+
empty_hashugar = Hashugar.new({})
|
113
|
+
hashugar = Hashugar.new({a: 1})
|
114
|
+
expect(empty_hashugar.empty?).to be true
|
115
|
+
expect(hashugar.empty?).to be false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashugar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jan Suchal
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-12-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: benchmark_suite
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: ffi
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: hashr
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Nested OpenStruct optimized for short-lived objects.
|
@@ -82,8 +73,8 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
86
|
-
- .rvmrc
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rvmrc"
|
87
78
|
- Gemfile
|
88
79
|
- MIT-LICENSE
|
89
80
|
- README.md
|
@@ -96,26 +87,26 @@ files:
|
|
96
87
|
- spec/spec_helper.rb
|
97
88
|
homepage: http://github.com/jsuchal/hashugar
|
98
89
|
licenses: []
|
90
|
+
metadata: {}
|
99
91
|
post_install_message:
|
100
92
|
rdoc_options: []
|
101
93
|
require_paths:
|
102
94
|
- lib
|
103
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
96
|
requirements:
|
106
|
-
- -
|
97
|
+
- - ">="
|
107
98
|
- !ruby/object:Gem::Version
|
108
99
|
version: '0'
|
109
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
101
|
requirements:
|
112
|
-
- -
|
102
|
+
- - ">="
|
113
103
|
- !ruby/object:Gem::Version
|
114
104
|
version: '0'
|
115
105
|
requirements: []
|
116
106
|
rubyforge_project:
|
117
|
-
rubygems_version:
|
107
|
+
rubygems_version: 2.4.5
|
118
108
|
signing_key:
|
119
|
-
specification_version:
|
109
|
+
specification_version: 4
|
120
110
|
summary: Fast Nested OpenStruct
|
121
111
|
test_files: []
|
112
|
+
has_rdoc:
|