rash-alt-0.4.3/0000755000175000017500000000000013136302114012247 5ustar pravipravirash-alt-0.4.3/rash.gemspec0000644000175000017500000000175113136302114014555 0ustar pravipravi# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "rash/version" Gem::Specification.new do |s| s.name = %q{rash_alt} s.authors = ["tcocca", "Shigenobu Nishikawa"] 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, shishi.s.n@gmail.com} s.homepage = "https://github.com/shishi/rash_alt" 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', '~> 3.4' s.add_development_dependency 'rake', '~> 10.4' s.add_development_dependency 'rdoc', '~> 4.2' s.add_development_dependency 'rspec', '~> 3.4' 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 rash-alt-0.4.3/lib/0000755000175000017500000000000013136302114013015 5ustar pravipravirash-alt-0.4.3/lib/hashie/0000755000175000017500000000000013136302114014256 5ustar pravipravirash-alt-0.4.3/lib/hashie/mash/0000755000175000017500000000000013136302114015206 5ustar pravipravirash-alt-0.4.3/lib/hashie/mash/rash.rb0000644000175000017500000000212313136302114016466 0ustar pravipravirequire 'hashie/mash' module Hashie class Mash 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 end rash-alt-0.4.3/lib/rash.rb0000644000175000017500000000003313136302114014273 0ustar pravipravirequire 'hashie/mash/rash' rash-alt-0.4.3/lib/rash/0000755000175000017500000000000013136302114013752 5ustar pravipravirash-alt-0.4.3/lib/rash/version.rb0000644000175000017500000000004413136302114015762 0ustar pravipravimodule Rash VERSION = '0.4.3' end rash-alt-0.4.3/.travis.yml0000644000175000017500000000007613136302114014363 0ustar pravipravilanguage: ruby script: 'bundle exec rake spec' rvm: - 2.3.0 rash-alt-0.4.3/README.rdoc0000644000175000017500000000444313136302114014062 0ustar pravipravi= rash {Gem Version}[https://badge.fury.io/rb/rash_alt] {Build Status}[https://travis-ci.org/shishi/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) == Installation Add this line to your application's Gemfile: gem 'rash_alt', require: 'rash' And then execute: $ bundle Or install it yourself as: $ gem install rash_alt == Usage @rash = Hashie::Mash::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. * Copyright (c) 2016 Shigenobu Nishikawa. === 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 rash-alt-0.4.3/.gitignore0000644000175000017500000000024513136302114014240 0ustar pravipravi## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## PROJECT::GENERAL coverage rdoc pkg ## PROJECT::SPECIFIC Gemfile.lock *.gem rash-alt-0.4.3/LICENSE0000644000175000017500000000210413136302114013251 0ustar pravipraviCopyright (c) 2009 Tom Cocca Copyright (c) 2016 Shigenobu Nishikawa 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. rash-alt-0.4.3/Rakefile0000644000175000017500000000065713136302114013724 0ustar pravipravirequire '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 rash-alt-0.4.3/Gemfile0000644000175000017500000000004413136302114013540 0ustar pravipravisource "http://rubygems.org" gemspecrash-alt-0.4.3/.rspec0000644000175000017500000000005213136302114013361 0ustar pravipravi--color --format=documentation --backtracerash-alt-0.4.3/spec/0000755000175000017500000000000013136302114013201 5ustar pravipravirash-alt-0.4.3/spec/rash_spec.rb0000644000175000017500000000712013136302114015475 0ustar pravipravirequire 'spec_helper' describe Hashie::Mash::Rash do subject { Hashie::Mash::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::Mash::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::Mash::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::Mash::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::Mash::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::Mash::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::Mash::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 rash-alt-0.4.3/spec/spec_helper.rb0000644000175000017500000000026213136302114016017 0ustar pravipravirequire File.expand_path('../../lib/rash', __FILE__) require 'rspec' RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = [:should, :expect] end end