pax_global_header00006660000000000000000000000064121471464770014527gustar00rootroot0000000000000052 comment=1a64e33eada5206a50aae20e7994f94c61640c6d ruby-rash-0.4.0/000077500000000000000000000000001214714647700134445ustar00rootroot00000000000000ruby-rash-0.4.0/.document000066400000000000000000000000741214714647700152640ustar00rootroot00000000000000README.rdoc lib/**/*.rb bin/* features/**/*.feature LICENSE ruby-rash-0.4.0/.gemtest000066400000000000000000000000001214714647700151030ustar00rootroot00000000000000ruby-rash-0.4.0/.gitignore000066400000000000000000000002451214714647700154350ustar00rootroot00000000000000## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## PROJECT::GENERAL coverage rdoc pkg ## PROJECT::SPECIFIC Gemfile.lock *.gem ruby-rash-0.4.0/.rspec000066400000000000000000000000431214714647700145560ustar00rootroot00000000000000--color --format=nested --backtraceruby-rash-0.4.0/Gemfile000066400000000000000000000000441214714647700147350ustar00rootroot00000000000000source "http://rubygems.org" gemspecruby-rash-0.4.0/LICENSE000066400000000000000000000020351214714647700144510ustar00rootroot00000000000000Copyright (c) 2009 Tom Cocca Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-rash-0.4.0/README.rdoc000066400000000000000000000035661214714647700152640ustar00rootroot00000000000000= rash Rash is an extension to Hashie ( http://github.com/intridea/hashie ) Rash subclasses Hashie::Mash to convert all keys in the hash to underscore The purpose of this is when working w/ Java (or any other apis) that return hashes (including nested) that have camelCased keys You will now be able to access those keys through underscored key names (camelCase still available) == Usage @rash = Hashie::Rash.new({ "varOne" => 1, "two" => 2, :three => 3, :varFour => 4, "fiveHumpHumps" => 5, :nested => { "NestedOne" => "One", :two => "two", "nested_three" => "three" }, "nestedTwo" => { "nested_two" => 22, :nestedThree => 23 } }) @rash.var_one # => 1 @rash.two # => 2 @rash.three # => 3 @rash.var_four # => 4 @rash.five_hump_humps # => 5 @rash.nested.nested_one # => "One" @rash.nested.two # => "two" @rash.nested.nested_three # => "three" @rash.nested_two.nested_two # => 22 @rash.nested_two.nested_three # => 23 == Note on Patches/Pull Requests * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit, do not mess with rakefile, version, or history. (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) * Send me a pull request. Bonus points for topic branches. == Copyright Copyright (c) 2010 Tom Cocca. See LICENSE for details. === Acknowledgements * Intridea (https://github.com/intridea) for Hashie * Mislav Marohnić (https://github.com/mislav) for contributions to Rash * Steve Agalloco (https://github.com/spagalloco) for updating Rash to use bundler, rspec 2.5, hashie 1.0 and fixing some load dependencies ruby-rash-0.4.0/Rakefile000066400000000000000000000006571214714647700151210ustar00rootroot00000000000000require 'bundler' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task :test => :spec task :default => :spec require 'rdoc/task' require File.expand_path('../lib/rash/version', __FILE__) RDoc::Task.new do |rdoc| version = Rash::VERSION rdoc.rdoc_dir = 'rdoc' rdoc.title = "rash #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end ruby-rash-0.4.0/lib/000077500000000000000000000000001214714647700142125ustar00rootroot00000000000000ruby-rash-0.4.0/lib/hashie/000077500000000000000000000000001214714647700154535ustar00rootroot00000000000000ruby-rash-0.4.0/lib/hashie/rash.rb000066400000000000000000000017741214714647700167460ustar00rootroot00000000000000require 'hashie/mash' module Hashie class Rash < Mash protected def convert_key(key) #:nodoc: underscore_string(key.to_s) end # Unlike its parent Mash, a Rash will convert other Hashie::Hash values to a Rash when assigning # instead of respecting the existing subclass def convert_value(val, duping=false) #:nodoc: case val when self.class val.dup when ::Hash val = val.dup if duping self.class.new(val) when Array val.collect{ |e| convert_value(e) } else val end end # converts a camel_cased string to a underscore string # subs spaces with underscores, strips whitespace # Same way ActiveSupport does string.underscore def underscore_string(str) str.to_s.strip. gsub(' ', '_'). gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). squeeze("_"). downcase end end end ruby-rash-0.4.0/lib/rash.rb000066400000000000000000000000251214714647700154710ustar00rootroot00000000000000require 'hashie/rash'ruby-rash-0.4.0/lib/rash/000077500000000000000000000000001214714647700151475ustar00rootroot00000000000000ruby-rash-0.4.0/lib/rash/version.rb000066400000000000000000000000431214714647700171560ustar00rootroot00000000000000module Rash VERSION = '0.4.0' endruby-rash-0.4.0/metadata.yml000066400000000000000000000054121214714647700157510ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: rash version: !ruby/object:Gem::Version hash: 15 prerelease: segments: - 0 - 4 - 0 version: 0.4.0 platform: ruby authors: - tcocca autorequire: bindir: bin cert_chain: [] date: 2013-02-27 00:00:00 -05:00 default_executable: dependencies: - !ruby/object:Gem::Dependency requirement: &id001 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 15 segments: - 2 - 0 - 0 version: 2.0.0 name: hashie type: :runtime prerelease: false version_requirements: *id001 - !ruby/object:Gem::Dependency requirement: &id002 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 25 segments: - 0 - 9 version: "0.9" name: rake type: :development prerelease: false version_requirements: *id002 - !ruby/object:Gem::Dependency requirement: &id003 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 21 segments: - 3 - 9 version: "3.9" name: rdoc type: :development prerelease: false version_requirements: *id003 - !ruby/object:Gem::Dependency requirement: &id004 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 9 segments: - 2 - 5 version: "2.5" name: rspec type: :development prerelease: false version_requirements: *id004 description: simple extension to Hashie::Mash for rubyified keys, all keys are converted to underscore to eliminate horrible camelCasing email: tom.cocca@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - .document - .gemtest - .gitignore - .rspec - Gemfile - LICENSE - README.rdoc - Rakefile - lib/hashie/rash.rb - lib/rash.rb - lib/rash/version.rb - rash.gemspec - spec/rash_spec.rb - spec/spec_helper.rb has_rdoc: true homepage: http://github.com/tcocca/rash licenses: [] post_install_message: rdoc_options: - --charset=UTF-8 require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" requirements: [] rubyforge_project: rubygems_version: 1.4.2 signing_key: specification_version: 3 summary: simple extension to Hashie::Mash for rubyified keys test_files: - spec/rash_spec.rb - spec/spec_helper.rb ruby-rash-0.4.0/rash.gemspec000066400000000000000000000016661214714647700157570ustar00rootroot00000000000000# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "rash/version" Gem::Specification.new do |s| s.name = %q{rash} s.authors = ["tcocca"] s.description = %q{simple extension to Hashie::Mash for rubyified keys, all keys are converted to underscore to eliminate horrible camelCasing} s.email = %q{tom.cocca@gmail.com} s.homepage = %q{http://github.com/tcocca/rash} s.rdoc_options = ["--charset=UTF-8"] s.summary = %q{simple extension to Hashie::Mash for rubyified keys} s.version = Rash::VERSION s.add_dependency 'hashie', '~> 2.0.0' s.add_development_dependency 'rake', '~> 0.9' s.add_development_dependency 'rdoc', '~> 3.9' s.add_development_dependency 'rspec', '~> 2.5' s.require_paths = ['lib'] s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } end ruby-rash-0.4.0/spec/000077500000000000000000000000001214714647700143765ustar00rootroot00000000000000ruby-rash-0.4.0/spec/rash_spec.rb000066400000000000000000000070401214714647700166730ustar00rootroot00000000000000require 'spec_helper' describe Hashie::Rash do subject { Hashie::Rash.new({ "varOne" => 1, "two" => 2, :three => 3, :varFour => 4, "fiveHumpHumps" => 5, :nested => { "NestedOne" => "One", :two => "two", "nested_three" => "three" }, "nestedTwo" => { "nested_two" => 22, :nestedThree => 23 }, "spaced Key" => "When would this happen?", "trailing spaces " => "better safe than sorry", "extra spaces" => "hopefully this never happens" }) } it { should be_a(Hashie::Mash) } it "should create a new rash where all the keys are underscored instead of camelcased" do subject.var_one.should == 1 subject.two.should == 2 subject.three.should == 3 subject.var_four.should == 4 subject.five_hump_humps.should == 5 subject.nested.should be_a(Hashie::Rash) subject.nested.nested_one.should == "One" subject.nested.two.should == "two" subject.nested.nested_three.should == "three" subject.nested_two.should be_a(Hashie::Rash) subject.nested_two.nested_two.should == 22 subject.nested_two.nested_three.should == 23 subject.spaced_key.should == "When would this happen?" subject.trailing_spaces.should == "better safe than sorry" subject.extra_spaces.should == "hopefully this never happens" end it "should allow camelCased accessors" do subject.varOne.should == 1 subject.varOne = "once" subject.varOne.should == "once" subject.var_one.should == "once" end it "should allow camelCased accessors on nested hashes" do subject.nested.nestedOne.should == "One" subject.nested.nestedOne = "once" subject.nested.nested_one.should == "once" end it "should merge well with a Mash" do merged = subject.merge Hashie::Mash.new( :nested => {:fourTimes => "a charm"}, :nested3 => {:helloWorld => "hi"} ) merged.nested.four_times.should == "a charm" merged.nested.fourTimes.should == "a charm" merged.nested3.should be_a(Hashie::Rash) merged.nested3.hello_world.should == "hi" merged.nested3.helloWorld.should == "hi" merged[:nested3][:helloWorld].should == "hi" end it "should update well with a Mash" do subject.update Hashie::Mash.new( :nested => {:fourTimes => "a charm"}, :nested3 => {:helloWorld => "hi"} ) subject.nested.four_times.should == "a charm" subject.nested.fourTimes.should == "a charm" subject.nested3.should be_a(Hashie::Rash) subject.nested3.hello_world.should == "hi" subject.nested3.helloWorld.should == "hi" subject[:nested3][:helloWorld].should == "hi" end it "should merge well with a Hash" do merged = subject.merge({ :nested => {:fourTimes => "work like a charm"}, :nested3 => {:helloWorld => "hi"} }) merged.nested.four_times.should == "work like a charm" merged.nested.fourTimes.should == "work like a charm" merged.nested3.should be_a(Hashie::Rash) merged.nested3.hello_world.should == "hi" merged.nested3.helloWorld.should == "hi" merged[:nested3][:helloWorld].should == "hi" end it "should handle assigning a new Hash and convert it to a rash" do subject.nested3 = {:helloWorld => "hi"} subject.nested3.should be_a(Hashie::Rash) subject.nested3.hello_world.should == "hi" subject.nested3.helloWorld.should == "hi" subject[:nested3][:helloWorld].should == "hi" end it "should allow initializing reader" do subject.nested3!.helloWorld = "hi" subject.nested3.hello_world.should == "hi" end end ruby-rash-0.4.0/spec/spec_helper.rb000066400000000000000000000001061214714647700172110ustar00rootroot00000000000000require File.expand_path('../../lib/rash', __FILE__) require 'rspec'