insensitive_hash 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,6 @@
1
+ ### 0.2.1 / 2012/02/10
2
+ * Bug fix: Insensitive `fetch`
3
+
1
4
  ### 0.2.0 / 2012/02/01
2
5
  * Major rewrite
3
6
  * Constructor syntaxes have been changed to match those of standard Hash (not backward-compatible)
@@ -87,6 +87,11 @@ class InsensitiveHash < Hash
87
87
  keys.map { |k| self[k] }
88
88
  end
89
89
 
90
+ def fetch *args, &block
91
+ args[0] = lookup_key(args[0]) if args.first
92
+ super *args, &block
93
+ end
94
+
90
95
  private
91
96
  def self.wrap value
92
97
  case value
@@ -1,3 +1,3 @@
1
1
  class InsensitiveHash < Hash
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -235,11 +235,6 @@ class TestInsensitiveHash < Test::Unit::TestCase
235
235
  assert_equal 3, h.each.count
236
236
  end
237
237
 
238
- def test_fetch
239
- h = InsensitiveHash[{ :a => 1, :b => 2, :c => 3}]
240
- assert_raise(KeyError) { h.fetch('D') }
241
- end
242
-
243
238
  def test_has_value
244
239
  h = InsensitiveHash[{ :a => 1, :b => 2, :c => 3}]
245
240
  assert h.value?(3)
@@ -272,5 +267,16 @@ class TestInsensitiveHash < Test::Unit::TestCase
272
267
  h = InsensitiveHash[{:a => 1, :b => 2}]
273
268
  assert_equal [2, 1], h.values_at('B', :A)
274
269
  end
270
+
271
+ def test_fetch
272
+ h = InsensitiveHash[{:a => 1, :b => 2}]
273
+ ['a', 'A', :A].each do |k|
274
+ assert_equal 1, h.fetch(k)
275
+ assert_equal 1, h.fetch(k) { nil }
276
+ end
277
+ assert_equal 3, h.fetch(:c, 3)
278
+ assert_equal 3, h.fetch(:c) { 3 }
279
+ assert_raise(KeyError) { h.fetch('D') }
280
+ end
275
281
  end
276
282
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insensitive_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
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: 2012-02-01 00:00:00.000000000 Z
12
+ date: 2012-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
16
- requirement: &2156362640 !ruby/object:Gem::Requirement
16
+ requirement: &2152981220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.3.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156362640
24
+ version_requirements: *2152981220
25
25
  description: Hash with case-insensitive, Symbol/String-indifferent key access
26
26
  email:
27
27
  - junegunn.c@gmail.com