hipsterhash 0.0.1
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/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/hipsterhash.gemspec +20 -0
- data/lib/hipster_hash.rb +17 -0
- data/lib/hipsterhash.rb +2 -0
- data/test/hipster_hash_test.rb +28 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Bryan JJ Buckley
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Hipsterhash
|
2
|
+
|
3
|
+
A completely indifferent Hash.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hipsterhash'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install hipsterhash
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
hh = HipsterHash.new
|
23
|
+
hh[:foo_bar] = "Pigs"
|
24
|
+
hh["FooBar"] # => "Pigs"
|
25
|
+
```
|
26
|
+
|
27
|
+
It uses [ActiveSupport][1] [Inflectors][2] internally, so you can probably muck
|
28
|
+
around with them to modify the behaviour.
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
37
|
+
|
38
|
+
[1]: https://github.com/rails/rails/tree/master/activesupport/lib/active_support
|
39
|
+
[2]: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/inflections.rb
|
data/Rakefile
ADDED
data/hipsterhash.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "hipsterhash"
|
7
|
+
gem.version = "0.0.1"
|
8
|
+
gem.authors = ["Bryan JJ Buckley"]
|
9
|
+
gem.email = ["jjbuckley@gmail.com"]
|
10
|
+
gem.description = %q{A hash which is all, like, whatever.}
|
11
|
+
gem.summary = %q{A HipsterHash is just like a regular ruby Hash, except that it doesn't distinguish between symbols or strings, and the keys are case insensitive.}
|
12
|
+
gem.homepage = "http://jjbuckley.github.com/hipsterhash"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency "activesupport"
|
20
|
+
end
|
data/lib/hipster_hash.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'active_support/hash_with_indifferent_access'
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
|
+
|
5
|
+
# A HipsterHash is like a regular Hash, except the keys are semi case
|
6
|
+
# insensitive, and symbols and strings are equivalent. Therefore, :foo_bar,
|
7
|
+
# :FooBar, and "foo_bar" are considered to be the same key.
|
8
|
+
class HipsterHash < HashWithIndifferentAccess
|
9
|
+
def [](key, *extras)
|
10
|
+
super(convert_key(key), *extras)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
def convert_key(k)
|
15
|
+
k.to_s.underscore.to_sym
|
16
|
+
end
|
17
|
+
end
|
data/lib/hipsterhash.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.expand_path('../../lib/hipster_hash', __FILE__)
|
4
|
+
|
5
|
+
class HipsterHashTest < Test::Unit::TestCase
|
6
|
+
def test_normal_behaviour
|
7
|
+
hh = HipsterHash.new
|
8
|
+
hh["foo"] = "bar"
|
9
|
+
assert_kind_of Hash, hh
|
10
|
+
assert_equal "bar", hh[:foo]
|
11
|
+
assert_nil hh[:pigs]
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_indifference_to_input_type
|
15
|
+
hh = HipsterHash.new({ :foo => "bar" })
|
16
|
+
assert_equal "bar", hh["foo"]
|
17
|
+
hh['foo'] = "baz"
|
18
|
+
assert_equal "baz", hh[:foo]
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_case_indifference
|
22
|
+
hh = HipsterHash.new
|
23
|
+
hh[:foo_bar] = "bar"
|
24
|
+
assert_equal "bar", hh["FooBar"]
|
25
|
+
hh['FooBar'] = "baz"
|
26
|
+
assert_equal "baz", hh[:foo_bar]
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hipsterhash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bryan JJ Buckley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A hash which is all, like, whatever.
|
31
|
+
email:
|
32
|
+
- jjbuckley@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- hipsterhash.gemspec
|
43
|
+
- lib/hipster_hash.rb
|
44
|
+
- lib/hipsterhash.rb
|
45
|
+
- test/hipster_hash_test.rb
|
46
|
+
homepage: http://jjbuckley.github.com/hipsterhash
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A HipsterHash is just like a regular ruby Hash, except that it doesn't distinguish
|
70
|
+
between symbols or strings, and the keys are case insensitive.
|
71
|
+
test_files:
|
72
|
+
- test/hipster_hash_test.rb
|