hashr 0.0.12 → 0.0.13

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.
data/Rakefile CHANGED
@@ -3,7 +3,9 @@ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'lib' << 'test'
6
- t.pattern = 'test/**/*_test.rb'
6
+ # this currently does not work in rake 0.9.2, 0.9.3 will fix it
7
+ # t.pattern = 'test/**/*_test.rb'
8
+ t.test_files = FileList['test/**/*_test.rb']
7
9
  t.verbose = false
8
10
  end
9
11
 
data/lib/hashr.rb CHANGED
@@ -31,6 +31,10 @@ class Hashr < Hash
31
31
  (class << self; self; end).class_eval(&block) if block_given?
32
32
  end
33
33
 
34
+ def [](key)
35
+ super(key.to_sym)
36
+ end
37
+
34
38
  def []=(key, value)
35
39
  super(key, value.is_a?(Hash) ? self.class.new(value, {}) : value)
36
40
  end
data/lib/hashr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hashr < Hash
2
- VERSION = "0.0.12"
2
+ VERSION = '0.0.13'
3
3
  end
data/test/hashr_test.rb CHANGED
@@ -10,39 +10,47 @@ class HashrTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  test 'method access on an existing key returns the value' do
13
- assert_equal 'foo', Hashr.new({ :foo => 'foo' }).foo
13
+ assert_equal 'foo', Hashr.new(:foo => 'foo').foo
14
14
  end
15
15
 
16
16
  test 'method access on a non-existing key returns nil when raise_missing_keys is false' do
17
17
  Hashr.raise_missing_keys = false
18
- assert_nil Hashr.new({ :foo => 'foo' }).bar
18
+ assert_nil Hashr.new(:foo => 'foo').bar
19
19
  end
20
20
 
21
21
  test 'method access on a non-existing key raises an IndexError when raise_missing_keys is true' do
22
22
  Hashr.raise_missing_keys = true
23
- assert_raises(IndexError) { Hashr.new({ :foo => 'foo' }).bar }
23
+ assert_raises(IndexError) { Hashr.new(:foo => 'foo').bar }
24
24
  end
25
25
 
26
26
  test 'method access on an existing nested key returns the value' do
27
- assert_equal 'bar', Hashr.new({ :foo => { :bar => 'bar' } }).foo.bar
27
+ assert_equal 'bar', Hashr.new(:foo => { :bar => 'bar' }).foo.bar
28
28
  end
29
29
 
30
30
  test 'method access on a non-existing nested key returns nil when raise_missing_keys is false' do
31
31
  Hashr.raise_missing_keys = false
32
- assert_nil Hashr.new({ :foo => { :bar => 'bar' } }).foo.baz
32
+ assert_nil Hashr.new(:foo => { :bar => 'bar' }).foo.baz
33
33
  end
34
34
 
35
35
  test 'method access on a non-existing nested key raises an IndexError when raise_missing_keys is true' do
36
36
  Hashr.raise_missing_keys = true
37
- assert_raises(IndexError) { Hashr.new({ :foo => { :bar => 'bar' } }).foo.baz }
37
+ assert_raises(IndexError) { Hashr.new(:foo => { :bar => 'bar' }).foo.baz }
38
38
  end
39
39
 
40
40
  test 'method access with a question mark returns true if the key has a value' do
41
- assert_equal true, Hashr.new({ :foo => { :bar => 'bar' } }).foo.bar?
41
+ assert_equal true, Hashr.new(:foo => { :bar => 'bar' }).foo.bar?
42
42
  end
43
43
 
44
44
  test 'method access with a question mark returns false if the key does not have a value' do
45
- assert_equal false, Hashr.new({ :foo => { :bar => 'bar' } }).foo.baz?
45
+ assert_equal false, Hashr.new(:foo => { :bar => 'bar' }).foo.baz?
46
+ end
47
+
48
+ test 'hash access is indifferent about symbols/strings (string data given, symbol keys used)' do
49
+ assert_equal 'bar', Hashr.new('foo' => { 'bar' => 'bar' })[:foo][:bar]
50
+ end
51
+
52
+ test 'hash access is indifferent about symbols/strings (symbol data given, string keys used)' do
53
+ assert_equal 'bar', Hashr.new(:foo => { :bar => 'bar' })['foo']['bar']
46
54
  end
47
55
 
48
56
  test 'mixing symbol and string keys in defaults and data' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-24 00:00:00.000000000 Z
12
+ date: 2011-08-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70320929512120 !ruby/object:Gem::Requirement
16
+ requirement: &70271315078720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70320929512120
24
+ version_requirements: *70271315078720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: test_declarative
27
- requirement: &70320929511400 !ruby/object:Gem::Requirement
27
+ requirement: &70271315078080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.0.2
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70320929511400
35
+ version_requirements: *70271315078080
36
36
  description: Simple Hash extension to make working with nested hashes (e.g. for configuration)
37
37
  easier and less error-prone.
38
38
  email: svenfuchs@artweb-design.de