unrash 0.5.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a25b46a697313aaab12fa99ab8e76bd54b98008a
4
+ data.tar.gz: a8f64ed3cf715b19773e5bbfbbd15b9f40a32880
5
+ SHA512:
6
+ metadata.gz: e4f7d20fbe5755d660019ddb99ceb9fa07933d2c677513b17834facc5d10060a31bfb042158307dca5c191db3557572d22d819a518b28e5571d09a6b56eba4c8
7
+ data.tar.gz: 951f1010c690cc3f5fb251061e395fa0c41927e27aabab824603ca86a54136a7c3421b40220268595a825347c8e82b92ebdbdcd28e4afbd155166118ebeea849
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
File without changes
@@ -0,0 +1,26 @@
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
+ ## RubyMine
17
+ /.idea
18
+
19
+ ## PROJECT::GENERAL
20
+ coverage
21
+ rdoc
22
+ pkg
23
+
24
+ ## PROJECT::SPECIFIC
25
+ Gemfile.lock
26
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
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.
@@ -0,0 +1,102 @@
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::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
+ = Unrash
42
+
43
+ Unrash is an extension to Hashie ( http://github.com/intridea/hashie )
44
+
45
+ Unrash subclasses Hashie::Mash to convert all keys in the hash to lower camel case
46
+
47
+ The purpose of this is when working w/ Java (or any other apis) and need to send hashes (including nested) that need to be
48
+ camelCased keys
49
+
50
+ You will now be able to access those keys through camelCase key names (underscored still available)
51
+
52
+ == Usage
53
+
54
+ @unrash = Hashie::UnRash.new({
55
+ "var_one" => 1,
56
+ "two" => 2,
57
+ :three => 3,
58
+ :var_four => 4,
59
+ "five_hump_humps" => 5,
60
+ :nested => {
61
+ "nested_one" => "One",
62
+ :two => "two",
63
+ "nested_three" => "three"
64
+ },
65
+ "nested_wwo" => {
66
+ "nested_two" => 22,
67
+ :nested_three => 23
68
+ }
69
+ })
70
+
71
+ @unrash.varOne # => 1
72
+ @unrash.two # => 2
73
+ @unrash.three # => 3
74
+ @unrash.varFour # => 4
75
+ @unrash.fiveHumpHumps # => 5
76
+ @unrash.nested.nestedOne # => "One"
77
+ @unrash.nested.two # => "two"
78
+ @unrash.nested.nestedThree # => "three"
79
+ @unrash.nestedTwo.nestedTwo # => 22
80
+ @unrash.nestedTwo.nestedThree # => 23
81
+
82
+
83
+ == Note on Patches/Pull Requests
84
+
85
+ * Fork the project.
86
+ * Make your feature addition or bug fix.
87
+ * Add tests for it. This is important so I don't break it in a
88
+ future version unintentionally.
89
+ * Commit, do not mess with rakefile, version, or history.
90
+ (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)
91
+ * Send me a pull request. Bonus points for topic branches.
92
+
93
+ == Copyright
94
+
95
+ Copyright (c) 2010 Tom Cocca. See LICENSE for details.
96
+
97
+ === Acknowledgements
98
+
99
+ * Intridea (https://github.com/intridea) for Hashie
100
+ * Mislav Marohnić (https://github.com/mislav) for contributions to Rash
101
+ * Steve Agalloco (https://github.com/spagalloco) for updating Rash to use bundler, rspec 2.5, hashie 1.0 and fixing some load dependencies
102
+ * Sebastian Ortiz (https://github.com/neoecos) for the implementation of Unrash
@@ -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/unrash/version', __FILE__)
12
+ RDoc::Task.new do |rdoc|
13
+ version = Unrash::VERSION
14
+
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = "unrash #{version}"
17
+ rdoc.rdoc_files.include('README*')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'hashie/mash'
2
+
3
+ module Hashie
4
+ class Unrash < Mash
5
+
6
+ protected
7
+
8
+ def convert_key(key) #:nodoc:
9
+ camel_case_lower(key.to_s)
10
+ end
11
+
12
+ # Unlike its parent Mash, a Unrash will convert other Hashie::Hash values to a Unrash when assigning
13
+ # instead of respecting the existing subclass
14
+ def convert_value(val, duping=false) #:nodoc:
15
+ case val
16
+ when self.class
17
+ val.dup
18
+ when ::Hash
19
+ val = val.dup if duping
20
+ self.class.new(val)
21
+ when Array
22
+ val.collect{ |e| convert_value(e) }
23
+ else
24
+ val
25
+ end
26
+ end
27
+
28
+ # converts a underscore string to a lowerCamelCase string
29
+ def camel_case_lower(str)
30
+ str.strip().gsub(' ','').split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
31
+ end
32
+
33
+ def camel_case(str)
34
+ return str if str !~ /_/ && str =~ /[A-Z]+.*/
35
+ str.strip().gsub(' ','').split('_').map{|e| e.capitalize}.join
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1 @@
1
+ require 'hashie/unrash'
@@ -0,0 +1,3 @@
1
+ module Unrash
2
+ VERSION = '0.5.0'
3
+ end
@@ -0,0 +1,3 @@
1
+ require File.expand_path('../../lib/unrash', __FILE__)
2
+
3
+ require 'rspec'
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hashie::Unrash do
4
+ subject {
5
+ Hashie::Unrash.new({
6
+ "var_one" => 1,
7
+ "two" => 2,
8
+ :three => 3,
9
+ :var_four => 4,
10
+ "five_hump_humps" => 5,
11
+ :nested => {
12
+ "nested_one" => "One",
13
+ :two => "two",
14
+ "nested_three" => "three"
15
+ },
16
+ "nested_two" => {
17
+ "nested_two" => 22,
18
+ :nested_three => 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 unrash where all the keys are camelcased instead of underscored" do
29
+ subject.varOne.should == 1
30
+ subject.two.should == 2
31
+ subject.three.should == 3
32
+ subject.varFour.should == 4
33
+ subject.fiveHumpHumps.should == 5
34
+ subject.nested.should be_a(Hashie::Unrash)
35
+ subject.nested.nestedOne.should == "One"
36
+ subject.nested.two.should == "two"
37
+ subject.nested.nested_three.should == "three"
38
+ subject.nestedTwo.should be_a(Hashie::Unrash)
39
+ subject.nestedTwo.nestedTwo.should == 22
40
+ subject.nestedTwo.nestedThree.should == 23
41
+ subject.spacedKey.should == "When would this happen?"
42
+ subject.trailingSpaces.should == "better safe than sorry"
43
+ subject.extraSpaces.should == "hopefully this never happens"
44
+ end
45
+
46
+ it "should allow underscored accessors" do
47
+ subject.var_one.should == 1
48
+ subject.var_one = "once"
49
+ subject.var_one.should == "once"
50
+ subject.varOne.should == "once"
51
+ end
52
+
53
+ it "should allow underscored accessors on nested hashes" do
54
+ subject.nested.nested_one.should == "One"
55
+ subject.nested.nested_one = "once"
56
+ subject.nested.nestedOne.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::Unrash)
68
+ merged.nested3.helloWorld.should == "hi"
69
+ merged.nested3.hello_world.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 => {:four_times => "a charm"},
76
+ :nested3 => {:hello_world => "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::Unrash)
82
+ subject.nested3.hello_world.should == "hi"
83
+ subject.nested3.helloWorld.should == "hi"
84
+ subject[:nested3][:hello_world].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::Unrash)
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 unrash" do
102
+ subject.nested3 = {:helloWorld => "hi"}
103
+
104
+ subject.nested3.should be_a(Hashie::Unrash)
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,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "unrash/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{unrash}
7
+ s.authors = ["Sebastian Ortiz V"]
8
+ s.description = %q{simple extension to Hashie::Mash for non rubyified keys, all keys are converted to camelCase}
9
+ s.email = %q{neoecos@gmail.com}
10
+ s.homepage = %q{http://github.com/neoecos/rash}
11
+ s.rdoc_options = ["--charset=UTF-8"]
12
+ s.summary = %q{simple extension to Hashie::Mash for rubyified keys}
13
+
14
+ s.version = Unrash::VERSION
15
+
16
+ s.add_dependency 'hashie', '~> 2.0.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
+
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
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unrash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Ortiz V
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-22 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: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.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
+ description: simple extension to Hashie::Mash for non rubyified keys, all keys are
70
+ converted to camelCase
71
+ email: neoecos@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".document"
77
+ - ".gemtest"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.rdoc
83
+ - Rakefile
84
+ - lib/hashie/unrash.rb
85
+ - lib/unrash.rb
86
+ - lib/unrash/version.rb
87
+ - spec/spec_helper.rb
88
+ - spec/unrash_spec.rb
89
+ - unrash.gemspec
90
+ homepage: http://github.com/neoecos/rash
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options:
95
+ - "--charset=UTF-8"
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: simple extension to Hashie::Mash for rubyified keys
114
+ test_files: []