rack-indifferent 1.1.0 → 1.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +12 -7
- data/Rakefile +4 -30
- data/lib/rack/indifferent.rb +31 -7
- data/spec/indifferent_spec.rb +15 -17
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6eeac559ad3836d054b7c541846f37b298de8300
|
4
|
+
data.tar.gz: 34845a381540a1a33357e3c1d7519214139e1234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69602aadf87abb0056624104297d87b37bc5af159043445d27e30065c02da8de73f22a387961996e35ed0873c2c32500b5659b7104b5079770a3f447150dcfda
|
7
|
+
data.tar.gz: dee47d84bd98c6fdffb0ea349b51f58319bcc60c310c321a1ee75fb901eb9027bd476c18f4183ea7c84a40c3deead264f284c0693d58572a99a4913ab3924847
|
data/CHANGELOG
CHANGED
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
= rack-indifferent
|
2
2
|
|
3
|
-
rack-indifferent
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
rack-indifferent modifiesrack to make the hash it stores query params in
|
4
|
+
support indifferent access. This allows web frameworks/applications that
|
5
|
+
use rack-indifferent don't have to make a deep copy of the params to allow
|
6
|
+
indifferent access to the params.
|
7
7
|
|
8
8
|
== Installation
|
9
9
|
|
@@ -15,12 +15,17 @@ Source code is available on GitHub at https://github.com/jeremyevans/rack-indiff
|
|
15
15
|
|
16
16
|
== Basic Usage
|
17
17
|
|
18
|
-
|
19
|
-
the library:
|
18
|
+
You just need to require the library:
|
20
19
|
|
21
20
|
require 'rack/indifferent'
|
22
21
|
|
23
|
-
|
22
|
+
On rack 1, this will monkey patch a rack class to change the query params hashes
|
23
|
+
that rack uses to use indifferent access.
|
24
|
+
|
25
|
+
On rack 2, this will set a new default query parser that uses hashes with
|
26
|
+
indifferent access. Note that web frameworks and applications that use
|
27
|
+
custom query parsers in their request class will not be affected by
|
28
|
+
rack-indifferent.
|
24
29
|
|
25
30
|
== License
|
26
31
|
|
data/Rakefile
CHANGED
@@ -8,34 +8,8 @@ task :package=>[:clean] do |p|
|
|
8
8
|
sh %{#{FileUtils::RUBY} -S gem build rack-indifferent.gemspec}
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
begin
|
15
|
-
# RSpec 1
|
16
|
-
require "spec/rake/spectask"
|
17
|
-
spec_class = Spec::Rake::SpecTask
|
18
|
-
spec_files_meth = :spec_files=
|
19
|
-
rescue LoadError
|
20
|
-
# RSpec 2
|
21
|
-
require "rspec/core/rake_task"
|
22
|
-
spec_class = RSpec::Core::RakeTask
|
23
|
-
spec_files_meth = :pattern=
|
24
|
-
end
|
25
|
-
|
26
|
-
spec = lambda do |name, files, d|
|
27
|
-
lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'lib')
|
28
|
-
ENV['RUBYLIB'] ? (ENV['RUBYLIB'] += ":#{lib_dir}") : (ENV['RUBYLIB'] = lib_dir)
|
29
|
-
desc d
|
30
|
-
spec_class.new(name) do |t|
|
31
|
-
t.send(spec_files_meth, files)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
task :default => [:spec]
|
36
|
-
spec.call("spec", Dir["spec/*_spec.rb"], "Run specs")
|
37
|
-
rescue LoadError
|
38
|
-
task :default do
|
39
|
-
puts "Must install rspec to run the default task (which runs specs)"
|
40
|
-
end
|
11
|
+
desc "Build rack-indifferent gem"
|
12
|
+
task :spec do |p|
|
13
|
+
sh %{#{FileUtils::RUBY} -rubygems -I lib spec/indifferent_spec.rb}
|
41
14
|
end
|
15
|
+
task :default => :spec
|
data/lib/rack/indifferent.rb
CHANGED
@@ -1,12 +1,36 @@
|
|
1
|
+
require 'rack'
|
1
2
|
require 'rack/utils'
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
if Rack.release > '2'
|
5
|
+
module Rack::Indifferent
|
6
|
+
class QueryParser < Rack::QueryParser
|
7
|
+
# Work around for invalid optimization in rack
|
8
|
+
def parse_nested_query(qs, d=nil)
|
9
|
+
return make_params.to_params_hash if qs.nil? || qs.empty?
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
class Params < Rack::QueryParser::Params
|
14
|
+
INDIFFERENT_PROC = lambda{|h,k| h[k.to_s] if k.is_a?(Symbol)}
|
5
15
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
16
|
+
def initialize(limit = Rack::Utils.key_space_limit)
|
17
|
+
@limit = limit
|
18
|
+
@size = 0
|
19
|
+
@params = Hash.new(&INDIFFERENT_PROC)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Rack::Utils.default_query_parser = new(Params, 65536, 100)
|
24
|
+
end
|
10
25
|
end
|
11
|
-
|
26
|
+
else
|
27
|
+
class Rack::Utils::KeySpaceConstrainedParams
|
28
|
+
INDIFFERENT_PROC = lambda{|h,k| h[k.to_s] if k.is_a?(Symbol)}
|
12
29
|
|
30
|
+
def initialize(limit = Rack::Utils.key_space_limit)
|
31
|
+
@limit = limit
|
32
|
+
@size = 0
|
33
|
+
@params = Hash.new(&INDIFFERENT_PROC)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/indifferent_spec.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/rack/indifferent')
|
2
2
|
require 'rack/mock'
|
3
|
-
|
4
|
-
if defined?(RSpec)
|
5
|
-
require 'rspec/version'
|
6
|
-
if RSpec::Version::STRING >= '2.11.0'
|
7
|
-
RSpec.configure do |config|
|
8
|
-
config.expect_with :rspec do |c|
|
9
|
-
c.syntax = :should
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
3
|
+
require 'minitest/autorun'
|
14
4
|
|
15
5
|
describe 'rack-indifferent' do
|
16
6
|
it "should make requests use indifferent param hashes" do
|
17
7
|
params = Rack::Request.new(Rack::MockRequest.env_for('/?a=b&c[d]=e&f[][g]=h', :input=>'i=j&k[l]=m&n[][o]=p', :method=>'POST')).params
|
18
|
-
params[:a].
|
19
|
-
params[:c][:d].
|
20
|
-
params[:f][0][:g].
|
21
|
-
params[:i].
|
22
|
-
params[:k][:l].
|
23
|
-
params[:n][0][:o].
|
8
|
+
params[:a].must_equal 'b'
|
9
|
+
params[:c][:d].must_equal 'e'
|
10
|
+
params[:f][0][:g].must_equal 'h'
|
11
|
+
params[:i].must_equal 'j'
|
12
|
+
params[:k][:l].must_equal 'm'
|
13
|
+
params[:n][0][:o].must_equal 'p'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should make requests handle empty params" do
|
17
|
+
params = Rack::Request.new(Rack::MockRequest.env_for('/', :input=>'i=j&k[l]=m&n[][o]=p', :method=>'POST')).params
|
18
|
+
params[:a].must_equal nil
|
19
|
+
params[:i].must_equal 'j'
|
20
|
+
params[:k][:l].must_equal 'm'
|
21
|
+
params[:n][0][:o].must_equal 'p'
|
24
22
|
end
|
25
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-indifferent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.5.1
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Fast indifferent access to request params
|