uri-query_params 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ doc
2
+ pkg
3
+ tmp/*
4
+ .DS_Store
5
+ .bundle
6
+ .yardoc
7
+ *.db
8
+ *.log
9
+ *.swp
10
+ *~
data/ChangeLog.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.6.0 / 2011-12-06
2
+
3
+ * Allow {URI::QueryParams.parse} to yield query-params, in the order they were
4
+ parsed.
5
+
1
6
  ### 0.5.4 / 2011-03-19
2
7
 
3
8
  * Fixed a bug when parsing query params containing `&&&&`.
data/Rakefile CHANGED
@@ -7,8 +7,8 @@ begin
7
7
 
8
8
  Ore::Tasks.new
9
9
  rescue LoadError => e
10
- STDERR.puts e.message
11
- STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
10
+ warn e.message
11
+ warn "Run `gem install ore-tasks` to install 'ore/tasks'."
12
12
  end
13
13
 
14
14
  begin
@@ -14,6 +14,15 @@ module URI
14
14
  # @param [String] query_string
15
15
  # The URI query string.
16
16
  #
17
+ # @yield [name,value]
18
+ # The given block will be passed each parsed query param.
19
+ #
20
+ # @yieldparam [String] name
21
+ # The name of the query param.
22
+ #
23
+ # @yieldparam [String] value
24
+ # The value of the query param.
25
+ #
17
26
  # @return [Hash{String => String}]
18
27
  # The parsed query parameters.
19
28
  #
@@ -25,6 +34,10 @@ module URI
25
34
  # QueryParams.parse("x=a%20b%20c&y")
26
35
  # # => {"x"=>"a b c", "y"=>""}
27
36
  #
37
+ # @note
38
+ # Version 0.6.0 allows {parse} to yield the query params, in the order
39
+ # they are parsed.
40
+ #
28
41
  def QueryParams.parse(query_string)
29
42
  query_params = {}
30
43
 
@@ -34,12 +47,14 @@ module URI
34
47
  next if param.empty?
35
48
 
36
49
  name, value = param.split('=',2)
50
+ value = if value
51
+ URI.unescape(value)
52
+ else
53
+ ''
54
+ end
37
55
 
38
- if value
39
- query_params[name] = URI.unescape(value)
40
- else
41
- query_params[name] = ''
42
- end
56
+ yield(name,value) if block_given?
57
+ query_params[name] = value
43
58
  end
44
59
  end
45
60
 
@@ -1,6 +1,6 @@
1
1
  module URI
2
2
  module QueryParams
3
3
  # uri-query_params version
4
- VERSION = '0.5.4'
4
+ VERSION = '0.6.0'
5
5
  end
6
6
  end
@@ -42,6 +42,28 @@ describe URI::QueryParams do
42
42
  query_params['x'].should == '1'
43
43
  query_params['y'].should == '2'
44
44
  end
45
+
46
+ context "when given a block" do
47
+ it "should yield the duplicate named query params" do
48
+ params = []
49
+
50
+ subject.parse('z=1&z=2&z=3') do |name,value|
51
+ params << [name, value]
52
+ end
53
+
54
+ params.should == [['z', '1'], ['z', '2'], ['z', '3']]
55
+ end
56
+
57
+ it "should yield the query params in the order they are parsed" do
58
+ params = []
59
+
60
+ subject.parse('z=1&y=2&x=3') do |name,value|
61
+ params << [name, value]
62
+ end
63
+
64
+ params.should == [['z', '1'], ['y', '2'], ['x', '3']]
65
+ end
66
+ end
45
67
  end
46
68
 
47
69
  describe "dump" do
@@ -1,15 +1,127 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- begin
4
- Ore::Specification.new do |gemspec|
5
- # custom logic here
6
- end
7
- rescue NameError
8
- begin
9
- require 'ore/specification'
10
- retry
11
- rescue LoadError
12
- STDERR.puts "The 'uri-query_params.gemspec' file requires Ore."
13
- STDERR.puts "Run `gem install ore-core` to install Ore."
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gemspec|
6
+ files = if File.directory?('.git')
7
+ `git ls-files`.split($/)
8
+ elsif File.directory?('.hg')
9
+ `hg manifest`.split($/)
10
+ elsif File.directory?('.svn')
11
+ `svn ls -R`.split($/).select { |path| File.file?(path) }
12
+ else
13
+ Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
14
+ end
15
+
16
+ filter_files = lambda { |paths|
17
+ case paths
18
+ when Array
19
+ (files & paths)
20
+ when String
21
+ (files & Dir[paths])
22
+ end
23
+ }
24
+
25
+ version = {
26
+ :file => 'lib/uri/query_params/version.rb',
27
+ :constant => 'URI::QueryParams::VERSION'
28
+ }
29
+
30
+ defaults = {
31
+ 'name' => File.basename(File.dirname(__FILE__)),
32
+ 'files' => files,
33
+ 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
34
+ 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
35
+ 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
36
+ }
37
+
38
+ metadata = defaults.merge(YAML.load_file('gemspec.yml'))
39
+
40
+ gemspec.name = metadata.fetch('name',defaults[:name])
41
+ gemspec.version = if metadata['version']
42
+ metadata['version']
43
+ elsif File.file?(version[:file])
44
+ require File.join('.',version[:file])
45
+ eval(version[:constant])
46
+ end
47
+
48
+ gemspec.summary = metadata.fetch('summary',metadata['description'])
49
+ gemspec.description = metadata.fetch('description',metadata['summary'])
50
+
51
+ case metadata['license']
52
+ when Array
53
+ gemspec.licenses = metadata['license']
54
+ when String
55
+ gemspec.license = metadata['license']
56
+ end
57
+
58
+ case metadata['authors']
59
+ when Array
60
+ gemspec.authors = metadata['authors']
61
+ when String
62
+ gemspec.author = metadata['authors']
63
+ end
64
+
65
+ gemspec.email = metadata['email']
66
+ gemspec.homepage = metadata['homepage']
67
+
68
+ case metadata['require_paths']
69
+ when Array
70
+ gemspec.require_paths = metadata['require_paths']
71
+ when String
72
+ gemspec.require_path = metadata['require_paths']
73
+ end
74
+
75
+ gemspec.files = filter_files[metadata['files']]
76
+
77
+ gemspec.executables = metadata['executables']
78
+ gemspec.extensions = metadata['extensions']
79
+
80
+ if Gem::VERSION < '1.7.'
81
+ gemspec.default_executable = gemspec.executables.first
82
+ end
83
+
84
+ gemspec.test_files = filter_files[metadata['test_files']]
85
+
86
+ unless gemspec.files.include?('.document')
87
+ gemspec.extra_rdoc_files = metadata['extra_doc_files']
88
+ end
89
+
90
+ gemspec.post_install_message = metadata['post_install_message']
91
+ gemspec.requirements = metadata['requirements']
92
+
93
+ if gemspec.respond_to?(:required_ruby_version=)
94
+ gemspec.required_ruby_version = metadata['required_ruby_version']
95
+ end
96
+
97
+ if gemspec.respond_to?(:required_rubygems_version=)
98
+ gemspec.required_rubygems_version = metadata['required_ruby_version']
99
+ end
100
+
101
+ parse_versions = lambda { |versions|
102
+ case versions
103
+ when Array
104
+ versions.map { |v| v.to_s }
105
+ when String
106
+ versions.split(/,\s*/)
107
+ end
108
+ }
109
+
110
+ if metadata['dependencies']
111
+ metadata['dependencies'].each do |name,versions|
112
+ gemspec.add_dependency(name,parse_versions[versions])
113
+ end
114
+ end
115
+
116
+ if metadata['runtime_dependencies']
117
+ metadata['runtime_dependencies'].each do |name,versions|
118
+ gemspec.add_runtime_dependency(name,parse_versions[versions])
119
+ end
120
+ end
121
+
122
+ if metadata['development_dependencies']
123
+ metadata['development_dependencies'].each do |name,versions|
124
+ gemspec.add_development_dependency(name,parse_versions[versions])
125
+ end
14
126
  end
15
127
  end
metadata CHANGED
@@ -1,65 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: uri-query_params
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
4
5
  prerelease:
5
- version: 0.5.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Postmodern
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-03-19 00:00:00 -04:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: ore-tasks
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &18100340 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
18
+ requirements:
22
19
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: "0.4"
20
+ - !ruby/object:Gem::Version
21
+ version: '0.4'
25
22
  type: :development
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *18100340
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &18099820 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: "2.4"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.4'
36
33
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: yard
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *18099820
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &18099340 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
40
+ requirements:
44
41
  - - ~>
45
- - !ruby/object:Gem::Version
42
+ - !ruby/object:Gem::Version
46
43
  version: 0.6.0
47
44
  type: :development
48
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *18099340
49
47
  description: Allows access to the query component of the URI as a Hash.
50
- email:
51
- - postmodern.mod3@gmail.com
48
+ email: postmodern.mod3@gmail.com
52
49
  executables: []
53
-
54
50
  extensions: []
55
-
56
- extra_rdoc_files:
57
- - README.md
58
- - ChangeLog.md
59
- - LICENSE.txt
60
- files:
51
+ extra_rdoc_files: []
52
+ files:
61
53
  - .document
62
54
  - .gemtest
55
+ - .gitignore
63
56
  - .rspec
64
57
  - .yardopts
65
58
  - ChangeLog.md
@@ -80,35 +73,33 @@ files:
80
73
  - spec/query_params_spec.rb
81
74
  - spec/spec_helper.rb
82
75
  - uri-query_params.gemspec
83
- has_rdoc: yard
84
76
  homepage: http://github.com/postmodern/uri-query_params
85
- licenses:
77
+ licenses:
86
78
  - MIT
87
79
  post_install_message:
88
80
  rdoc_options: []
89
-
90
- require_paths:
81
+ require_paths:
91
82
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ required_ruby_version: !ruby/object:Gem::Requirement
93
84
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
98
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
90
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: "0"
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
104
95
  requirements: []
105
-
106
- rubyforge_project: uri-query_params
107
- rubygems_version: 1.6.2
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.10
108
98
  signing_key:
109
99
  specification_version: 3
110
100
  summary: Access the query parameters of a URI, just like $_GET in PHP.
111
- test_files:
112
- - spec/query_params_spec.rb
113
- - spec/extensions/https_spec.rb
101
+ test_files:
114
102
  - spec/extensions/http_spec.rb
103
+ - spec/extensions/https_spec.rb
104
+ - spec/query_params_spec.rb
105
+ has_rdoc: