sinatra-param 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sinatra/param.rb +4 -0
- data/lib/sinatra/param/version.rb +1 -1
- data/sinatra-param-1.0.1.gem +0 -0
- data/sinatra-param.gemspec +1 -0
- data/spec/dummy/app.rb +16 -1
- data/spec/parameter_spec.rb +19 -0
- data/spec/parameter_type_coercion_spec.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 677024a927239579882a3b2704ba877a74681056
|
4
|
+
data.tar.gz: afb52e16b6977a93b758620db199fff2b99fb87e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe0e5afbe4f15d5007cfff11267ceeebf4edb33dbc60e5952fb044238fb92f7f6c72a87839b35716f9cda78e0320429027d09b24666beaec8eee745aae5d3dd5
|
7
|
+
data.tar.gz: 260669c49e78b131d802fdb838af6d33edca7b551424e1a9732fd0322800f7709fed8e4a7188a5cc2c4b836a1a1b78085ca9a53763c7173e2b561a79329f2dff
|
data/Gemfile.lock
CHANGED
data/lib/sinatra/param.rb
CHANGED
@@ -10,6 +10,10 @@ module Sinatra
|
|
10
10
|
class InvalidParameterError < StandardError; end
|
11
11
|
|
12
12
|
def param(name, type, options = {})
|
13
|
+
name = name.to_s
|
14
|
+
|
15
|
+
return unless params.member?(name) or present?(options[:default]) or options[:required]
|
16
|
+
|
13
17
|
begin
|
14
18
|
params[name] = coerce(params[name], type, options) || options[:default]
|
15
19
|
params[name] = options[:transform].to_proc.call(params[name]) if options[:transform]
|
Binary file
|
data/sinatra-param.gemspec
CHANGED
data/spec/dummy/app.rb
CHANGED
@@ -10,8 +10,23 @@ class App < Sinatra::Base
|
|
10
10
|
content_type :json
|
11
11
|
end
|
12
12
|
|
13
|
+
get '/' do
|
14
|
+
param :a, String
|
15
|
+
param :b, String, required: true
|
16
|
+
param :c, String, default: 'test'
|
17
|
+
param :d, String
|
18
|
+
|
19
|
+
params.to_json
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/keys/stringify' do
|
23
|
+
param :q, String, transform: :upcase
|
24
|
+
|
25
|
+
params['q']
|
26
|
+
end
|
27
|
+
|
13
28
|
get '/coerce/string' do
|
14
|
-
params[
|
29
|
+
params['arg'] = params['arg'].to_i
|
15
30
|
param :arg, String
|
16
31
|
params.to_json
|
17
32
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Parameter' do
|
4
|
+
it 'only sets parameters present in request or with a default value' do
|
5
|
+
get('/', a: 'a', b: 'b') do |response|
|
6
|
+
response_body = JSON.parse(response.body)
|
7
|
+
response_body.member?('a').should eq true
|
8
|
+
response_body.member?('b').should eq true
|
9
|
+
response_body.member?('c').should eq true
|
10
|
+
response_body.member?('d').should eq false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'stringifies parameters' do
|
15
|
+
get('/keys/stringify', q: 'test') do |response|
|
16
|
+
response.body.should eq 'TEST'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -32,7 +32,7 @@ describe 'Parameter Types' do
|
|
32
32
|
it 'coerces time' do
|
33
33
|
get('/coerce/time', arg: '20130117') do |response|
|
34
34
|
response.status.should == 200
|
35
|
-
JSON.parse(response.body)['arg'].should
|
35
|
+
JSON.parse(response.body)['arg'].should match(/2013-01-17 00:00:00/)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-param
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattt Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -141,15 +141,18 @@ files:
|
|
141
141
|
- ./Rakefile
|
142
142
|
- ./README.md
|
143
143
|
- ./sinatra-param-1.0.0.gem
|
144
|
+
- ./sinatra-param-1.0.1.gem
|
144
145
|
- ./sinatra-param.gemspec
|
145
146
|
- spec/dummy/app.rb
|
146
147
|
- spec/parameter_sets_spec.rb
|
148
|
+
- spec/parameter_spec.rb
|
147
149
|
- spec/parameter_transformations_spec.rb
|
148
150
|
- spec/parameter_type_coercion_spec.rb
|
149
151
|
- spec/parameter_validations_spec.rb
|
150
152
|
- spec/spec_helper.rb
|
151
153
|
homepage: https://github.com/mattt/sinatra-param
|
152
|
-
licenses:
|
154
|
+
licenses:
|
155
|
+
- MIT
|
153
156
|
metadata: {}
|
154
157
|
post_install_message:
|
155
158
|
rdoc_options: []
|
@@ -174,6 +177,7 @@ summary: Parameter Contracts for Sinatra
|
|
174
177
|
test_files:
|
175
178
|
- spec/dummy/app.rb
|
176
179
|
- spec/parameter_sets_spec.rb
|
180
|
+
- spec/parameter_spec.rb
|
177
181
|
- spec/parameter_transformations_spec.rb
|
178
182
|
- spec/parameter_type_coercion_spec.rb
|
179
183
|
- spec/parameter_validations_spec.rb
|