rash-alt-0.4.3/ 0000755 0001750 0001750 00000000000 13136302114 012247 5 ustar pravi pravi rash-alt-0.4.3/rash.gemspec 0000644 0001750 0001750 00000001751 13136302114 014555 0 ustar pravi pravi # -*- 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/ 0000755 0001750 0001750 00000000000 13136302114 013015 5 ustar pravi pravi rash-alt-0.4.3/lib/hashie/ 0000755 0001750 0001750 00000000000 13136302114 014256 5 ustar pravi pravi rash-alt-0.4.3/lib/hashie/mash/ 0000755 0001750 0001750 00000000000 13136302114 015206 5 ustar pravi pravi rash-alt-0.4.3/lib/hashie/mash/rash.rb 0000644 0001750 0001750 00000002123 13136302114 016466 0 ustar pravi pravi require '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.rb 0000644 0001750 0001750 00000000033 13136302114 014273 0 ustar pravi pravi require 'hashie/mash/rash'
rash-alt-0.4.3/lib/rash/ 0000755 0001750 0001750 00000000000 13136302114 013752 5 ustar pravi pravi rash-alt-0.4.3/lib/rash/version.rb 0000644 0001750 0001750 00000000044 13136302114 015762 0 ustar pravi pravi module Rash
VERSION = '0.4.3'
end
rash-alt-0.4.3/.travis.yml 0000644 0001750 0001750 00000000076 13136302114 014363 0 ustar pravi pravi language: ruby
script: 'bundle exec rake spec'
rvm:
- 2.3.0
rash-alt-0.4.3/README.rdoc 0000644 0001750 0001750 00000004443 13136302114 014062 0 ustar pravi pravi = rash
{
}[https://badge.fury.io/rb/rash_alt]
{
}[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/.gitignore 0000644 0001750 0001750 00000000245 13136302114 014240 0 ustar pravi pravi ## 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/LICENSE 0000644 0001750 0001750 00000002104 13136302114 013251 0 ustar pravi pravi Copyright (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/Rakefile 0000644 0001750 0001750 00000000657 13136302114 013724 0 ustar pravi pravi require '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/Gemfile 0000644 0001750 0001750 00000000044 13136302114 013540 0 ustar pravi pravi source "http://rubygems.org"
gemspec rash-alt-0.4.3/.rspec 0000644 0001750 0001750 00000000052 13136302114 013361 0 ustar pravi pravi --color
--format=documentation
--backtrace rash-alt-0.4.3/spec/ 0000755 0001750 0001750 00000000000 13136302114 013201 5 ustar pravi pravi rash-alt-0.4.3/spec/rash_spec.rb 0000644 0001750 0001750 00000007120 13136302114 015475 0 ustar pravi pravi require '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.rb 0000644 0001750 0001750 00000000262 13136302114 016017 0 ustar pravi pravi require File.expand_path('../../lib/rash', __FILE__)
require 'rspec'
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
end