pax_global_header00006660000000000000000000000064142047076200014514gustar00rootroot0000000000000052 comment=7b9434ec26665b72b63223f73245b90cde4bb3e1 rash_alt-0.4.12/000077500000000000000000000000001420470762000133755ustar00rootroot00000000000000rash_alt-0.4.12/.github/000077500000000000000000000000001420470762000147355ustar00rootroot00000000000000rash_alt-0.4.12/.github/workflows/000077500000000000000000000000001420470762000167725ustar00rootroot00000000000000rash_alt-0.4.12/.github/workflows/rspec.yml000066400000000000000000000011161420470762000206300ustar00rootroot00000000000000name: rspec on: push: branches: - master pull_request: branches: - "*" jobs: rspec: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-20.04, ubuntu-18.04] ruby: [2.5, 2.6, 2.7, 3.0] steps: - uses: actions/checkout@v2 with: fetch-depth: 1 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: install dependency run: bundle install - name: run spec run: bundle exec rake spec rash_alt-0.4.12/.gitignore000066400000000000000000000003211420470762000153610ustar00rootroot00000000000000## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## INTELLIJ .idea ## PROJECT::GENERAL coverage rdoc pkg ## PROJECT::SPECIFIC Gemfile.lock *.gem ## VScode .devcontainer rash_alt-0.4.12/.rspec000066400000000000000000000000521420470762000145070ustar00rootroot00000000000000--color --format=documentation --backtracerash_alt-0.4.12/Dockerfile000066400000000000000000000002451420470762000153700ustar00rootroot00000000000000FROM rubylang/ruby:3.1.0-focal WORKDIR /app RUN chown ubuntu:ubuntu /app ENV BUNDLE_PATH vendor/path USER ubuntu ADD --chown=ubuntu:ubuntu . . RUN bundle install rash_alt-0.4.12/Gemfile000066400000000000000000000000441420470762000146660ustar00rootroot00000000000000source "http://rubygems.org" gemspecrash_alt-0.4.12/LICENSE000066400000000000000000000021041420470762000143770ustar00rootroot00000000000000Copyright (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.12/README.md000066400000000000000000000053001420470762000146520ustar00rootroot00000000000000# rash [![gem version](https://img.shields.io/gem/v/rash_alt.svg)](https://rubygems.org/gems/rash_alt) [![build status](https://github.com/shishi/rash_alt/workflows/rspec/badge.svg)](https://github.com/shishi/rash_alt/actions?query=workflow%3Arspec) Rash is an extension to Hashie ( http://github.com/hashie/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: ```ruby gem 'rash_alt', require: 'rash' ``` And then execute: ```shell $ bundle ``` Or install it yourself as: ```shell $ gem install rash_alt ``` ## Usage ```ruby @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 ``` ## Known Issue You may have Hashie's warnings like this ``` WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash::Rash#varOne defined in Hashie::Mash::Rash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. ``` if you want to disable this, use `disable_warnings` https://github.com/hashie/hashie#mash ## 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.12/Rakefile000066400000000000000000000006571420470762000150520ustar00rootroot00000000000000require '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.12/lib/000077500000000000000000000000001420470762000141435ustar00rootroot00000000000000rash_alt-0.4.12/lib/hashie/000077500000000000000000000000001420470762000154045ustar00rootroot00000000000000rash_alt-0.4.12/lib/hashie/mash/000077500000000000000000000000001420470762000163345ustar00rootroot00000000000000rash_alt-0.4.12/lib/hashie/mash/rash.rb000066400000000000000000000022741420470762000176230ustar00rootroot00000000000000require 'hashie/mash' module Hashie class Mash class Rash < Mash # NOTE: I have no idea I should do all keys `disable_warnings` for avoiding Hashie v5's warnings 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.12/lib/rash.rb000066400000000000000000000000331420470762000154210ustar00rootroot00000000000000require 'hashie/mash/rash' rash_alt-0.4.12/lib/rash/000077500000000000000000000000001420470762000151005ustar00rootroot00000000000000rash_alt-0.4.12/lib/rash/version.rb000066400000000000000000000000451420470762000171110ustar00rootroot00000000000000module Rash VERSION = '0.4.12' end rash_alt-0.4.12/rash.gemspec000066400000000000000000000017511420470762000157030ustar00rootroot00000000000000# -*- 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@srevo.net} 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', '>= 13.0.3' s.add_development_dependency 'rdoc', '>= 6.3.0' 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.12/spec/000077500000000000000000000000001420470762000143275ustar00rootroot00000000000000rash_alt-0.4.12/spec/rash_spec.rb000066400000000000000000000104441420470762000166260ustar00rootroot00000000000000require 'spec_helper' require 'hashie' 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 }, :nestedThree => [ { :nestedFour => 4 }, { "nestedFour" => 4 } ], "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 #avoiding hashie v5- warnings subject.class.disable_warnings(:varOne) if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new("5.0.0") 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 # avoiding hashie v5- warnings subject.class.disable_warnings(:nestedOne) if Gem::Version.new(Hashie::VERSION) >= Gem::Version.new("5.0.0") 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 convert an array of Hashes" do subject.nested_three.should be_a(Array) subject.nested_three[0].should be_a(Hashie::Mash::Rash) subject.nested_three[0].nested_four.should == 4 subject.nested_three[1].should be_a(Hashie::Mash::Rash) subject.nested_three[1].nested_four.should == 4 end it "should allow initializing reader" do subject.nested3!.helloWorld = "hi" subject.nested3.hello_world.should == "hi" end end rash_alt-0.4.12/spec/spec_helper.rb000066400000000000000000000002621420470762000171450ustar00rootroot00000000000000require File.expand_path('../../lib/rash', __FILE__) require 'rspec' RSpec.configure do |config| config.expect_with :rspec do |c| c.syntax = [:should, :expect] end end