hashr 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/hashr/version.rb +1 -1
- data/lib/hashr.rb +7 -2
- data/test/hashr_test.rb +6 -0
- metadata +24 -24
data/Gemfile.lock
CHANGED
data/lib/hashr/version.rb
CHANGED
data/lib/hashr.rb
CHANGED
@@ -41,7 +41,8 @@ class Hashr < Hash
|
|
41
41
|
(class << self; self; end).class_eval(&block) if block_given?
|
42
42
|
end
|
43
43
|
|
44
|
-
def [](key)
|
44
|
+
def [](key, default = nil)
|
45
|
+
store(key.to_sym, Hashr.new(default)) if default && !key?(key)
|
45
46
|
super(key.to_sym)
|
46
47
|
end
|
47
48
|
|
@@ -49,6 +50,11 @@ class Hashr < Hash
|
|
49
50
|
super(key.to_sym, value.is_a?(Hash) ? self.class.new(value, {}) : value)
|
50
51
|
end
|
51
52
|
|
53
|
+
def set(path, value, stack = [])
|
54
|
+
tokens = path.to_s.split('.')
|
55
|
+
tokens.size == 1 ? self[path] = value : self[tokens.shift, Hashr.new].set(tokens.join('.'), value, stack)
|
56
|
+
end
|
57
|
+
|
52
58
|
def respond_to?(name)
|
53
59
|
true
|
54
60
|
end
|
@@ -117,4 +123,3 @@ class Hashr < Hash
|
|
117
123
|
hash
|
118
124
|
end
|
119
125
|
end
|
120
|
-
|
data/test/hashr_test.rb
CHANGED
@@ -198,5 +198,11 @@ class HashrTest < Test::Unit::TestCase
|
|
198
198
|
assert hash[:foo].instance_of?(Hash)
|
199
199
|
assert hash[:foo][:bar].instance_of?(Hash)
|
200
200
|
end
|
201
|
+
|
202
|
+
test 'set sets a dot separated path to nested hashes' do
|
203
|
+
hashr = Hashr.new(:foo => { :bar => 'bar' })
|
204
|
+
hashr.set('foo.baz', 'baz')
|
205
|
+
assert_equal 'baz', hashr.foo.baz
|
206
|
+
end
|
201
207
|
end
|
202
208
|
|
metadata
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.18
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sven Fuchs
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-27 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rake
|
16
|
-
|
17
|
-
none: false
|
17
|
+
version_requirements: &2530 !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
|
-
|
22
|
+
none: false
|
23
|
+
requirement: *2530
|
23
24
|
prerelease: false
|
24
|
-
|
25
|
+
type: :development
|
25
26
|
- !ruby/object:Gem::Dependency
|
26
27
|
name: test_declarative
|
27
|
-
|
28
|
-
none: false
|
28
|
+
version_requirements: &2548 !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.0.2
|
33
|
-
|
33
|
+
none: false
|
34
|
+
requirement: *2548
|
34
35
|
prerelease: false
|
35
|
-
|
36
|
-
description: Simple Hash extension to make working with nested hashes (e.g. for configuration)
|
37
|
-
easier and less error-prone.
|
36
|
+
type: :development
|
37
|
+
description: Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone.
|
38
38
|
email: svenfuchs@artweb-design.de
|
39
39
|
executables: []
|
40
40
|
extensions: []
|
41
41
|
extra_rdoc_files: []
|
42
42
|
files:
|
43
|
-
- lib/hashr
|
43
|
+
- lib/hashr.rb
|
44
44
|
- lib/hashr/env_defaults.rb
|
45
45
|
- lib/hashr/version.rb
|
46
|
-
- lib/hashr.rb
|
46
|
+
- lib/hashr/core_ext/ruby/hash.rb
|
47
47
|
- test/core_ext_test.rb
|
48
48
|
- test/hashr_test.rb
|
49
49
|
- test/test_helper.rb
|
@@ -52,30 +52,30 @@ files:
|
|
52
52
|
- MIT-LICENSE
|
53
53
|
- Rakefile
|
54
54
|
- README.md
|
55
|
+
has_rdoc: true
|
55
56
|
homepage: http://github.com/svenfuchs/hashr
|
56
57
|
licenses: []
|
57
|
-
post_install_message:
|
58
|
+
post_install_message:
|
58
59
|
rdoc_options: []
|
59
60
|
require_paths:
|
60
61
|
- lib
|
61
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
67
|
none: false
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
70
|
- - ! '>='
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
|
+
none: false
|
73
74
|
requirements: []
|
74
75
|
rubyforge_project: ! '[none]'
|
75
|
-
rubygems_version: 1.
|
76
|
-
signing_key:
|
76
|
+
rubygems_version: 1.5.1
|
77
|
+
signing_key:
|
77
78
|
specification_version: 3
|
78
|
-
summary: Simple Hash extension to make working with nested hashes (e.g. for configuration)
|
79
|
-
easier and less error-prone
|
79
|
+
summary: Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone
|
80
80
|
test_files: []
|
81
|
-
|
81
|
+
...
|