hash_tools 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c49be4b67ede742b42848405b4ac0226266a345
4
- data.tar.gz: e4d2509e181d2466bd4a2f42bbdd328c2f9bad4e
3
+ metadata.gz: 18fecec7d7499d73290542b45404f78aa73e6826
4
+ data.tar.gz: b5e668e9960f1ce84a595d34edd4b3a579cc716d
5
5
  SHA512:
6
- metadata.gz: 5e96a94e34f64344db9236a10bd12af7e8e726a00b9ba0b597be36c2ed7cdb15d1e7e62669eadf49ab91a250382fa2ac5d03981faa8a04f4a5bbc467dbc32046
7
- data.tar.gz: 2a1e88310651ce839db9e14c116b9df405917a347f2a3ceb8c2ace9ac3309c26ce35224625fa6bc1ea4a3fd8e56d5debcb4f2e89346d22d57f024096b7deb865
6
+ metadata.gz: c4cbf139964133adcfd7a5997b8478bed82dbd0429b0efef9386568e54a47d0b9bf86cfc6832108892911c6d875370b88ba7f1e7a39664937b615ea65c64f557
7
+ data.tar.gz: 0b82a9e0dc78a402cad1a06d8d6078b04edbf7f3b174d2caf5f3d5daad73a3831e1ddb33e8b7eb9da7270f83ab40c86c31cacfe19560cc36d890eeebd41e9625
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.1
4
+ - 2.2.0
5
+ cache: bundler
6
+ sudo: false
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # hash_tools
2
2
 
3
+ [![Build Status](https://travis-ci.org/WeTransfer/hash_tools.svg?branch=master)](https://travis-ci.org/WeTransfer/hash_tools)
4
+
3
5
  Do things to Hashes, without injecting methods into them or extending core classes of the language.
4
6
  And mostly without being too smart. Does not require ActiveSupport.
5
7
 
6
8
  Transforming the keys of a hash:
7
9
 
8
- HashTools::Transform.transform_keys_of({'foo' => 1}, &:upcase) #=> {'FOO' => 1}, works recursively
10
+ HashTools.transform_keys_of({'foo' => 1}, &:upcase) #=> {'FOO' => 1}, works recursively
9
11
 
10
12
  Fetching multiple values from a Hash:
11
13
 
@@ -32,6 +34,7 @@ A simple indifferent access proxy:
32
34
  h = {'foo'=>{bar: 2}}
33
35
  w = HashTools.indifferent(h)
34
36
  w[:foo][:bar] #=> 2
37
+ w.foo.bar #=> 2
35
38
 
36
39
  Check the documentation for the separate modules for more.
37
40
 
@@ -47,6 +50,6 @@ Check the documentation for the separate modules for more.
47
50
 
48
51
  ## Copyright
49
52
 
50
- Copyright (c) 2015 Julik Tarkhanov. See LICENSE.txt for
53
+ Copyright (c) 2015 WeTransfer. See LICENSE.txt for
51
54
  further details.
52
55
 
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: hash_tools 1.0.0 ruby lib
5
+ # stub: hash_tools 1.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "hash_tools"
9
- s.version = "1.0.0"
9
+ s.version = "1.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Julik Tarkhanov"]
14
- s.date = "2015-10-17"
14
+ s.date = "2015-11-02"
15
15
  s.description = "Do useful things to Ruby Hashes"
16
16
  s.email = "me@julik.nl"
17
17
  s.extra_rdoc_files = [
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.files = [
22
22
  ".document",
23
23
  ".rspec",
24
+ ".travis.yml",
24
25
  ".yardopts",
25
26
  "Gemfile",
26
27
  "LICENSE.txt",
@@ -1,5 +1,5 @@
1
1
  module HashTools
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
 
4
4
  require_relative 'hash_tools/indifferent'
5
5
 
@@ -82,6 +82,15 @@ class HashTools::Indifferent < SimpleDelegator
82
82
  end
83
83
  end
84
84
 
85
+ def method_missing(method_name, *args)
86
+ return self[method_name] if key?(method_name) && args.empty?
87
+ super
88
+ end
89
+
90
+ def respond_to_missing?(method_name)
91
+ key?(method_name)
92
+ end
93
+
85
94
  alias_method :has_key?, :key?
86
95
 
87
96
  private
@@ -15,9 +15,21 @@ describe HashTools::Indifferent do
15
15
  expect(wrapper.fetch('b')).to eq(2)
16
16
  expect(wrapper.fetch(:b)).to eq(2)
17
17
 
18
+ expect(wrapper.a).to eq(1)
19
+ expect(wrapper.b).to eq(2)
20
+
18
21
  expect(wrapper.keys).to eq(h_syms.keys)
19
22
  end
20
23
 
24
+ it 'raises NoMethodError when accessing missing keys via dot notation' do
25
+ h_syms = {a: 1, 'b' => 2}
26
+ wrapper = described_class.new(h_syms)
27
+
28
+ expect {
29
+ wrapper.c
30
+ }.to raise_error(NoMethodError)
31
+ end
32
+
21
33
  it 'supports indifferent access to deeply nested hashes' do
22
34
  h_deep = {a: {:b => 1, 'c' => 2}}
23
35
 
@@ -28,6 +40,9 @@ describe HashTools::Indifferent do
28
40
  expect(wrapper[:a][:c]).to eq(2)
29
41
  expect(wrapper['a']['c']).to eq(2)
30
42
 
43
+ expect(wrapper.a.b).to eq(1)
44
+ expect(wrapper.a.c).to eq(2)
45
+
31
46
  expect(wrapper.keys).to eq(h_deep.keys)
32
47
  end
33
48
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julik Tarkhanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-17 00:00:00.000000000 Z
11
+ date: 2015-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -68,6 +68,7 @@ extra_rdoc_files:
68
68
  files:
69
69
  - ".document"
70
70
  - ".rspec"
71
+ - ".travis.yml"
71
72
  - ".yardopts"
72
73
  - Gemfile
73
74
  - LICENSE.txt