rash_kesha_antonov 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +62 -0
- data/Rakefile +19 -0
- data/lib/hashie/hash/rash.rb +46 -0
- data/lib/rash.rb +1 -0
- data/lib/rash/version.rb +3 -0
- data/rash.gemspec +26 -0
- data/spec/rash_spec.rb +115 -0
- data/spec/spec_helper.rb +4 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1176dc596b5cc29f20ae7b2ac97e73e7c157165
|
4
|
+
data.tar.gz: ea4a59dbeb6bdae482e118a1bce4379878d5bddb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f4acb6c5c61e9061d532e60e54e201b8a56623f879277e3a84c876a63348e36dbd761a71a18ccf16b1167a0f487ab7243ee09f7853299fd9ee2a3f9d9bf89ec6
|
7
|
+
data.tar.gz: 679b1ad61bb0c46e89a311604b5ab1f66c1cd8db112033a495cc7ce95882b9e7b6ddb24fd1f3dda9e535ff2e357b6208e0b0a51d1c6b2362c3a7c28cef2aae61
|
data/.document
ADDED
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tom Cocca
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= rash
|
2
|
+
|
3
|
+
== This version of Rash has been modified to use an updated version of Hashie
|
4
|
+
|
5
|
+
Rash is an extension to Hashie ( http://github.com/intridea/hashie )
|
6
|
+
|
7
|
+
Rash subclasses Hashie::Mash to convert all keys in the hash to underscore
|
8
|
+
|
9
|
+
The purpose of this is when working w/ Java (or any other apis) that return hashes (including nested) that have camelCased keys
|
10
|
+
|
11
|
+
You will now be able to access those keys through underscored key names (camelCase still available)
|
12
|
+
|
13
|
+
== Usage
|
14
|
+
|
15
|
+
@rash = Hashie::Rash.new({
|
16
|
+
"varOne" => 1,
|
17
|
+
"two" => 2,
|
18
|
+
:three => 3,
|
19
|
+
:varFour => 4,
|
20
|
+
"fiveHumpHumps" => 5,
|
21
|
+
:nested => {
|
22
|
+
"NestedOne" => "One",
|
23
|
+
:two => "two",
|
24
|
+
"nested_three" => "three"
|
25
|
+
},
|
26
|
+
"nestedTwo" => {
|
27
|
+
"nested_two" => 22,
|
28
|
+
:nestedThree => 23
|
29
|
+
}
|
30
|
+
})
|
31
|
+
|
32
|
+
@rash.var_one # => 1
|
33
|
+
@rash.two # => 2
|
34
|
+
@rash.three # => 3
|
35
|
+
@rash.var_four # => 4
|
36
|
+
@rash.five_hump_humps # => 5
|
37
|
+
@rash.nested.nested_one # => "One"
|
38
|
+
@rash.nested.two # => "two"
|
39
|
+
@rash.nested.nested_three # => "three"
|
40
|
+
@rash.nested_two.nested_two # => 22
|
41
|
+
@rash.nested_two.nested_three # => 23
|
42
|
+
|
43
|
+
== Note on Patches/Pull Requests
|
44
|
+
|
45
|
+
* Fork the project.
|
46
|
+
* Make your feature addition or bug fix.
|
47
|
+
* Add tests for it. This is important so I don't break it in a
|
48
|
+
future version unintentionally.
|
49
|
+
* Commit, do not mess with rakefile, version, or history.
|
50
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
51
|
+
* Send me a pull request. Bonus points for topic branches.
|
52
|
+
|
53
|
+
== Copyright
|
54
|
+
|
55
|
+
Copyright (c) 2010 Tom Cocca. See LICENSE for details.
|
56
|
+
|
57
|
+
=== Acknowledgements
|
58
|
+
|
59
|
+
* Trocca (https://github.com/tcocca) for Rash
|
60
|
+
* Intridea (https://github.com/intridea) for Hashie
|
61
|
+
* Mislav Marohnić (https://github.com/mislav) for contributions to Rash
|
62
|
+
* Steve Agalloco (https://github.com/spagalloco) for updating Rash to use bundler, rspec 2.5, hashie 1.0 and fixing some load dependencies
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :test => :spec
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
require 'rdoc/task'
|
11
|
+
require File.expand_path('../lib/rash/version', __FILE__)
|
12
|
+
RDoc::Task.new do |rdoc|
|
13
|
+
version = Rash::VERSION
|
14
|
+
|
15
|
+
rdoc.rdoc_dir = 'rdoc'
|
16
|
+
rdoc.title = "rash #{version}"
|
17
|
+
rdoc.rdoc_files.include('README*')
|
18
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
19
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'hashie/hash'
|
2
|
+
require 'hashie/mash'
|
3
|
+
|
4
|
+
module Hashie
|
5
|
+
class Hash
|
6
|
+
class Rash < Hashie::Mash
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def convert_key(key) #:nodoc:
|
11
|
+
underscore_string(key.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Unlike its parent Mash, a Rash will convert other Hashie::Hash values to a Rash when assigning
|
15
|
+
# instead of respecting the existing subclass
|
16
|
+
def convert_value(val, duping=false) #:nodoc:
|
17
|
+
case val
|
18
|
+
when self.class
|
19
|
+
val.dup
|
20
|
+
when ::Hash
|
21
|
+
val = val.dup if duping
|
22
|
+
self.class.new(val)
|
23
|
+
when Array
|
24
|
+
val.collect{ |e| convert_value(e) }
|
25
|
+
else
|
26
|
+
val
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# converts a camel_cased string to a underscore string
|
31
|
+
# subs spaces with underscores, strips whitespace
|
32
|
+
# Same way ActiveSupport does string.underscore
|
33
|
+
def underscore_string(str)
|
34
|
+
str.to_s.strip.
|
35
|
+
gsub(' ', '_').
|
36
|
+
gsub(/::/, '/').
|
37
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
38
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
39
|
+
tr("-", "_").
|
40
|
+
squeeze("_").
|
41
|
+
downcase
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/rash.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'hashie/hash/rash'
|
data/lib/rash/version.rb
ADDED
data/rash.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rash/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{rash_kesha_antonov}
|
7
|
+
s.authors = ["tcocca, wzcolon"]
|
8
|
+
s.description = %q{simple extension to Hashie::Mash for rubyified keys, all keys are converted to underscore to eliminate horrible camelCasing}
|
9
|
+
s.email = %q{}
|
10
|
+
s.homepage = %q{http://github.com/wzcolon/rash}
|
11
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
12
|
+
s.summary = %q{simple extension to Hashie::Mash for rubyified keys}
|
13
|
+
|
14
|
+
s.version = Rash::VERSION
|
15
|
+
|
16
|
+
s.add_dependency 'hashie', '~> 3.0'
|
17
|
+
s.add_development_dependency 'rake', '~> 0.9'
|
18
|
+
s.add_development_dependency 'rdoc', '~> 3.9'
|
19
|
+
s.add_development_dependency 'rspec', '~> 2.5'
|
20
|
+
s.add_development_dependency 'pry'
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
end
|
data/spec/rash_spec.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hashie::Hash::Rash do
|
4
|
+
subject {
|
5
|
+
Hashie::Hash::Rash.new({
|
6
|
+
"varOne" => 1,
|
7
|
+
"two" => 2,
|
8
|
+
:three => 3,
|
9
|
+
:varFour => 4,
|
10
|
+
"fiveHumpHumps" => 5,
|
11
|
+
:nested => {
|
12
|
+
"NestedOne" => "One",
|
13
|
+
:two => "two",
|
14
|
+
"nested_three" => "three"
|
15
|
+
},
|
16
|
+
"nestedTwo" => {
|
17
|
+
"nested_two" => 22,
|
18
|
+
:nestedThree => 23
|
19
|
+
},
|
20
|
+
"spaced Key" => "When would this happen?",
|
21
|
+
"trailing spaces " => "better safe than sorry",
|
22
|
+
"extra spaces" => "hopefully this never happens"
|
23
|
+
})
|
24
|
+
}
|
25
|
+
|
26
|
+
it { should be_a(Hashie::Hash) }
|
27
|
+
|
28
|
+
it "should create a new rash where all the keys are underscored instead of camelcased" do
|
29
|
+
subject.var_one.should == 1
|
30
|
+
subject.two.should == 2
|
31
|
+
subject.three.should == 3
|
32
|
+
subject.var_four.should == 4
|
33
|
+
subject.five_hump_humps.should == 5
|
34
|
+
subject.nested.should be_a(Hashie::Hash::Rash)
|
35
|
+
subject.nested.nested_one.should == "One"
|
36
|
+
subject.nested.two.should == "two"
|
37
|
+
subject.nested.nested_three.should == "three"
|
38
|
+
subject.nested_two.should be_a(Hashie::Hash::Rash)
|
39
|
+
subject.nested_two.nested_two.should == 22
|
40
|
+
subject.nested_two.nested_three.should == 23
|
41
|
+
subject.spaced_key.should == "When would this happen?"
|
42
|
+
subject.trailing_spaces.should == "better safe than sorry"
|
43
|
+
subject.extra_spaces.should == "hopefully this never happens"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should allow camelCased accessors" do
|
47
|
+
subject.varOne.should == 1
|
48
|
+
subject.varOne = "once"
|
49
|
+
subject.varOne.should == "once"
|
50
|
+
subject.var_one.should == "once"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should allow camelCased accessors on nested hashes" do
|
54
|
+
subject.nested.nestedOne.should == "One"
|
55
|
+
subject.nested.nestedOne = "once"
|
56
|
+
subject.nested.nested_one.should == "once"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should merge well with a Mash" do
|
60
|
+
merged = subject.merge Hashie::Mash.new(
|
61
|
+
:nested => {:fourTimes => "a charm"},
|
62
|
+
:nested3 => {:helloWorld => "hi"}
|
63
|
+
)
|
64
|
+
|
65
|
+
merged.nested.four_times.should == "a charm"
|
66
|
+
merged.nested.fourTimes.should == "a charm"
|
67
|
+
merged.nested3.should be_a(Hashie::Hash::Rash)
|
68
|
+
merged.nested3.hello_world.should == "hi"
|
69
|
+
merged.nested3.helloWorld.should == "hi"
|
70
|
+
merged[:nested3][:helloWorld].should == "hi"
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should update well with a Mash" do
|
74
|
+
subject.update Hashie::Mash.new(
|
75
|
+
:nested => {:fourTimes => "a charm"},
|
76
|
+
:nested3 => {:helloWorld => "hi"}
|
77
|
+
)
|
78
|
+
|
79
|
+
subject.nested.four_times.should == "a charm"
|
80
|
+
subject.nested.fourTimes.should == "a charm"
|
81
|
+
subject.nested3.should be_a(Hashie::Hash::Rash)
|
82
|
+
subject.nested3.hello_world.should == "hi"
|
83
|
+
subject.nested3.helloWorld.should == "hi"
|
84
|
+
subject[:nested3][:helloWorld].should == "hi"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should merge well with a Hash" do
|
88
|
+
merged = subject.merge({
|
89
|
+
:nested => {:fourTimes => "work like a charm"},
|
90
|
+
:nested3 => {:helloWorld => "hi"}
|
91
|
+
})
|
92
|
+
|
93
|
+
merged.nested.four_times.should == "work like a charm"
|
94
|
+
merged.nested.fourTimes.should == "work like a charm"
|
95
|
+
merged.nested3.should be_a(Hashie::Hash::Rash)
|
96
|
+
merged.nested3.hello_world.should == "hi"
|
97
|
+
merged.nested3.helloWorld.should == "hi"
|
98
|
+
merged[:nested3][:helloWorld].should == "hi"
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should handle assigning a new Hash and convert it to a rash" do
|
102
|
+
subject.nested3 = {:helloWorld => "hi"}
|
103
|
+
|
104
|
+
subject.nested3.should be_a(Hashie::Hash::Rash)
|
105
|
+
subject.nested3.hello_world.should == "hi"
|
106
|
+
subject.nested3.helloWorld.should == "hi"
|
107
|
+
subject[:nested3][:helloWorld].should == "hi"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should allow initializing reader" do
|
111
|
+
subject.nested3!.helloWorld = "hi"
|
112
|
+
subject.nested3.hello_world.should == "hi"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rash_kesha_antonov
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tcocca, wzcolon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hashie
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: simple extension to Hashie::Mash for rubyified keys, all keys are converted
|
84
|
+
to underscore to eliminate horrible camelCasing
|
85
|
+
email: ''
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".document"
|
91
|
+
- ".gemtest"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- lib/hashie/hash/rash.rb
|
99
|
+
- lib/rash.rb
|
100
|
+
- lib/rash/version.rb
|
101
|
+
- rash.gemspec
|
102
|
+
- spec/rash_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: http://github.com/wzcolon/rash
|
105
|
+
licenses: []
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- "--charset=UTF-8"
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: simple extension to Hashie::Mash for rubyified keys
|
128
|
+
test_files:
|
129
|
+
- spec/rash_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
has_rdoc:
|