rash_alt 0.4.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1202fc69aaa357bca3b885f9e581c753c092f18a
4
+ data.tar.gz: dac581f3ce4ff0d3537ead12a0dd2f2c44a3abf5
5
+ SHA512:
6
+ metadata.gz: 6982e5d40d7b66710836cae2154ee30f206ab6abe41c69923a539783354181f17bf2bbbbfb50e78ace2a9df32d26a362068ad7436fba5da15c01001037523245
7
+ data.tar.gz: c361d9648ff347131cf95fef9be1da544ec117c84a77bbc052d83c7d51370dacd909a4596a5aad46f3fa24948d7e8e24a185bb9b6cc0b95287aeb641b1114d75
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ Gemfile.lock
23
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
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,59 @@
1
+ = rash
2
+
3
+ Rash is an extension to Hashie ( http://github.com/intridea/hashie )
4
+
5
+ Rash subclasses Hashie::Mash to convert all keys in the hash to underscore
6
+
7
+ The purpose of this is when working w/ Java (or any other apis) that return hashes (including nested) that have camelCased keys
8
+
9
+ You will now be able to access those keys through underscored key names (camelCase still available)
10
+
11
+ == Usage
12
+
13
+ @rash = Hashie::Mash::Rash.new({
14
+ "varOne" => 1,
15
+ "two" => 2,
16
+ :three => 3,
17
+ :varFour => 4,
18
+ "fiveHumpHumps" => 5,
19
+ :nested => {
20
+ "NestedOne" => "One",
21
+ :two => "two",
22
+ "nested_three" => "three"
23
+ },
24
+ "nestedTwo" => {
25
+ "nested_two" => 22,
26
+ :nestedThree => 23
27
+ }
28
+ })
29
+
30
+ @rash.var_one # => 1
31
+ @rash.two # => 2
32
+ @rash.three # => 3
33
+ @rash.var_four # => 4
34
+ @rash.five_hump_humps # => 5
35
+ @rash.nested.nested_one # => "One"
36
+ @rash.nested.two # => "two"
37
+ @rash.nested.nested_three # => "three"
38
+ @rash.nested_two.nested_two # => 22
39
+ @rash.nested_two.nested_three # => 23
40
+
41
+ == Note on Patches/Pull Requests
42
+
43
+ * Fork the project.
44
+ * Make your feature addition or bug fix.
45
+ * Add tests for it. This is important so I don't break it in a
46
+ future version unintentionally.
47
+ * Commit, do not mess with rakefile, version, or history.
48
+ (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)
49
+ * Send me a pull request. Bonus points for topic branches.
50
+
51
+ == Copyright
52
+
53
+ Copyright (c) 2010 Tom Cocca. See LICENSE for details.
54
+
55
+ === Acknowledgements
56
+
57
+ * Intridea (https://github.com/intridea) for Hashie
58
+ * Mislav Marohnić (https://github.com/mislav) for contributions to Rash
59
+ * 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,45 @@
1
+ require 'hashie/mash'
2
+
3
+ module Hashie
4
+ class Mash
5
+ class Rash < Mash
6
+
7
+ protected
8
+
9
+ def convert_key(key) #:nodoc:
10
+ underscore_string(key.to_s)
11
+ end
12
+
13
+ # Unlike its parent Mash, a Rash will convert other Hashie::Hash values to a Rash when assigning
14
+ # instead of respecting the existing subclass
15
+ def convert_value(val, duping=false) #:nodoc:
16
+ case val
17
+ when self.class
18
+ val.dup
19
+ when ::Hash
20
+ val = val.dup if duping
21
+ self.class.new(val)
22
+ when Array
23
+ val.collect{ |e| convert_value(e) }
24
+ else
25
+ val
26
+ end
27
+ end
28
+
29
+ # converts a camel_cased string to a underscore string
30
+ # subs spaces with underscores, strips whitespace
31
+ # Same way ActiveSupport does string.underscore
32
+ def underscore_string(str)
33
+ str.to_s.strip.
34
+ gsub(' ', '_').
35
+ gsub(/::/, '/').
36
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
37
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
38
+ tr("-", "_").
39
+ squeeze("_").
40
+ downcase
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Rash
2
+ VERSION = '0.4.0'
3
+ end
data/lib/rash.rb ADDED
@@ -0,0 +1 @@
1
+ require 'hashie/mash/rash'
data/rash.gemspec ADDED
@@ -0,0 +1,25 @@
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_alt}
7
+ s.authors = ["tcocca", "Shigenobu Nishikawa"]
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{tom.cocca@gmail.com, shishi.s.n@gmail.com}
10
+ s.homepage = "https://github.com/shishi/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.4'
17
+ s.add_development_dependency 'rake', '~> 10.4'
18
+ s.add_development_dependency 'rdoc', '~> 4.2'
19
+ s.add_development_dependency 'rspec', '~> 3.4'
20
+
21
+ s.require_paths = ['lib']
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ end
data/spec/rash_spec.rb ADDED
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hashie::Mash::Rash do
4
+ subject {
5
+ Hashie::Mash::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::Mash) }
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::Mash::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::Mash::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::Mash::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::Mash::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::Mash::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::Mash::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
@@ -0,0 +1,3 @@
1
+ require File.expand_path('../../lib/rash', __FILE__)
2
+
3
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rash_alt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - tcocca
8
+ - Shigenobu Nishikawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.4'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.4'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.4'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.4'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdoc
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '4.2'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '4.2'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.4'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.4'
70
+ description: simple extension to Hashie::Mash for rubyified keys, all keys are converted
71
+ to underscore to eliminate horrible camelCasing
72
+ email: tom.cocca@gmail.com, shishi.s.n@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".document"
78
+ - ".gemtest"
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.rdoc
84
+ - Rakefile
85
+ - lib/hashie/mash/rash.rb
86
+ - lib/rash.rb
87
+ - lib/rash/version.rb
88
+ - rash.gemspec
89
+ - spec/rash_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/shishi/rash
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options:
96
+ - "--charset=UTF-8"
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5.1
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: simple extension to Hashie::Mash for rubyified keys
115
+ test_files:
116
+ - spec/rash_spec.rb
117
+ - spec/spec_helper.rb