rack-param 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +1 -0
- data/lib/rack/param.rb +5 -4
- data/rack-param.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ec3ceacb0bc5616a90ea623585c15f6213901f6
|
4
|
+
data.tar.gz: 8112bc432b22048d15448cec448d28198ef8ed5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c9629493aca786b02202ae61fb7435e0d61a2a8a886e4ff988175b9232b8f0ca10f31d7d548377c8b1ae74361c8a2c25a7634bdaf665885e2495fc1c2a5d935
|
7
|
+
data.tar.gz: f9aad33b2aed468c98435862c64c67c9e46428a5cd4eedb78ff0daf56720f8391e064b863ec526dc48ea999c736fcb8d8e986d086b5be84021f2e6551daef2f5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,7 @@ Here's a list of options:
|
|
43
43
|
`:in` => Something that responds to `include?`<br />
|
44
44
|
`:regex` => A `Regexp`<br />
|
45
45
|
`:validator` => A block: `{ |param| true }`<br />
|
46
|
+
`:error_message` => A `String`. `$` is the parameter and `#` is the validator object. (`"Invalid password: $"`)
|
46
47
|
|
47
48
|
## Contributing
|
48
49
|
|
data/lib/rack/param.rb
CHANGED
@@ -53,8 +53,8 @@ module Rack
|
|
53
53
|
new message, &block
|
54
54
|
end
|
55
55
|
|
56
|
-
def validate param, value
|
57
|
-
return @message.sub(
|
56
|
+
def validate param, value, error_msg=nil
|
57
|
+
return (error_msg || @message).sub('$',"`#{param.to_s}`").sub('#',"`#{value.to_s}`") unless @block.call(param,value)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,6 +62,7 @@ module Rack
|
|
62
62
|
opts[:value].inspect
|
63
63
|
_opts = Hash[opts.dup.map { |k,v| [k.to_sym,v] }]
|
64
64
|
_opts.merge! _opts.delete(:conditions)
|
65
|
+
@error_message = opts.delete :error_message
|
65
66
|
@default = _opts.delete :default
|
66
67
|
@required = _opts.delete :required
|
67
68
|
@transform = _opts.delete :transform
|
@@ -107,8 +108,8 @@ module Rack
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
validate_error = opts.detect { |k,v| break rules[k].validate
|
111
|
-
return
|
111
|
+
validate_error = opts.detect { |k,v| break rules[k].validate @value, v, @error_message }
|
112
|
+
return validate_errorunless validate_error.nil?
|
112
113
|
|
113
114
|
@value = @transform.to_proc.call @value if @transform
|
114
115
|
nil
|
data/rack-param.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "rack-param"
|
7
|
-
spec.version = "0.1.
|
7
|
+
spec.version = "0.1.2"
|
8
8
|
spec.authors = ["Nathaniel Symer"]
|
9
9
|
spec.email = ["nate@natesymer.com"]
|
10
10
|
spec.summary = "Sane parameter validation for Rack::Request."
|