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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc4d0d398469bb52ab79a0948e317d1d125bff3d
4
- data.tar.gz: a10c62771b154aa046b3c89a2b1b7dc728cbf26b
3
+ metadata.gz: 677024a927239579882a3b2704ba877a74681056
4
+ data.tar.gz: afb52e16b6977a93b758620db199fff2b99fb87e
5
5
  SHA512:
6
- metadata.gz: 4e767c9fb0b92416432c59d53dd81b68ef9ad30250bdba869eaafc5b2415ac2d3319ad73d04b0a969b63bbbf16f8ab489be0b611540d3a38c6729e298975f639
7
- data.tar.gz: 40bcc930eb0df82c3f154f32467fa56985174a6603db678f5f7fe634dab8f1fd352ce36d50b5360a7cc4a3c4ed0e7f16312493e8cbabcffaa7b91944613032d2
6
+ metadata.gz: fe0e5afbe4f15d5007cfff11267ceeebf4edb33dbc60e5952fb044238fb92f7f6c72a87839b35716f9cda78e0320429027d09b24666beaec8eee745aae5d3dd5
7
+ data.tar.gz: 260669c49e78b131d802fdb838af6d33edca7b551424e1a9732fd0322800f7709fed8e4a7188a5cc2c4b836a1a1b78085ca9a53763c7173e2b561a79329f2dff
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-param (1.0.1)
4
+ sinatra-param (1.0.2)
5
5
  sinatra (~> 1.3)
6
6
 
7
7
  GEM
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]
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Param
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
Binary file
@@ -3,6 +3,7 @@ require File.expand_path('../lib/sinatra/param/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "sinatra-param"
6
+ s.license = "MIT"
6
7
  s.authors = ["Mattt Thompson"]
7
8
  s.email = "m@mattt.me"
8
9
  s.homepage = "https://github.com/mattt/sinatra-param"
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[:arg] = params[:arg].to_i
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 eq('2013-01-17 00:00:00 -0500')
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.1
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-17 00:00:00.000000000 Z
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