sinatra-browse 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -1
- data/lib/sinatra/browse/route.rb +6 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e596c2c094f363eec398cd2dc1c74d3d6cccbd9
|
4
|
+
data.tar.gz: 90b5732c3167897bb1cd6c6dcbed15d02b69e197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33205cac78eadc505f7c947ec7d79a23efdc7b592d6e0feed4a324f62b8374ad202947ce38cad9cf2ca251dd8c210fbfd088b74ddddc8c1f145c22f785b89950
|
7
|
+
data.tar.gz: 59ff1e796da21200d2b8f163f5a45611dbd2c0fd588b018978a787686fea630c07e56a1e023db7dd39563a4c989cb68d55b38f44a3c6c91973b81e81d972684b
|
data/README.md
CHANGED
@@ -90,12 +90,28 @@ param :small_prime_number, :Integer, in: Prime.take(10)
|
|
90
90
|
param :order, :String, in: ["ascending", "descending"]
|
91
91
|
```
|
92
92
|
|
93
|
-
|
93
|
+
### String validation
|
94
|
+
|
95
|
+
The following parameter validators can only be used for parameters of type `:String`.
|
96
|
+
|
97
|
+
`format` You can pass a regular expression that the string provided must match to.
|
94
98
|
|
95
99
|
```ruby
|
96
100
|
param :alphanumeric, :String, format: /^[0-9A-Za-z]*$/
|
97
101
|
```
|
98
102
|
|
103
|
+
`min_length` The string must be of this length or longer.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
param :five_or_longer, :String, min_length: 5
|
107
|
+
```
|
108
|
+
|
109
|
+
`max_length` The string must be of this length or shorter.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
param :five_or_shorter, :String, max_length: 5
|
113
|
+
```
|
114
|
+
|
99
115
|
## Parameter transformation
|
100
116
|
|
101
117
|
You can use transform to execute a quick method on any prameter provided. Anything that responds to *to_proc* will do.
|
data/lib/sinatra/browse/route.rb
CHANGED
@@ -63,7 +63,12 @@
|
|
63
63
|
if params[k]
|
64
64
|
return fail_validation k, params[k], v, :depends_on if v[:depends_on] && !params[v[:depends_on]]
|
65
65
|
return fail_validation k, params[k], v, :in if v[:in] && !v[:in].member?(params[k])
|
66
|
-
|
66
|
+
|
67
|
+
if v[:type] == :String
|
68
|
+
return fail_validation k, params[k], v, :format if v[:format] && !(params[k] =~ v[:format])
|
69
|
+
return fail_validation k, params[k], v, :min_length if v[:min_length] && params[k].length < v[:min_length]
|
70
|
+
return fail_validation k, params[k], v, :max_length if v[:max_length] && params[k].length > v[:max_length]
|
71
|
+
end
|
67
72
|
end
|
68
73
|
}
|
69
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-browse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Axsh Co. LTD
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Parameter declaration framework and browsable API for Sinatra
|
14
14
|
email: dev@axsh.net
|
@@ -17,8 +17,8 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/sinatra/browse.rb
|
20
|
-
- lib/sinatra/browse/route.rb
|
21
20
|
- lib/sinatra/browse/format.rb
|
21
|
+
- lib/sinatra/browse/route.rb
|
22
22
|
- LICENSE
|
23
23
|
- README.md
|
24
24
|
homepage: https://github.com/axsh/sinatra-browse
|
@@ -46,4 +46,3 @@ signing_key:
|
|
46
46
|
specification_version: 4
|
47
47
|
summary: Parameter declaration framework and browsable API for Sinatra
|
48
48
|
test_files: []
|
49
|
-
has_rdoc:
|