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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e233f217adb28e44d48871d58c6e656aa8d8e1e
4
- data.tar.gz: f769cccbc58260148238ed32d7c0b71e5fbadfe9
3
+ metadata.gz: 1ec3ceacb0bc5616a90ea623585c15f6213901f6
4
+ data.tar.gz: 8112bc432b22048d15448cec448d28198ef8ed5b
5
5
  SHA512:
6
- metadata.gz: 39af897f8210bf83eaba39929f01f212078ca019ad861608cba6db1e4b726d4639cf644d6c1020c4127c25156c902a14a22a8a6ea7f1d79b5c6c407786c99c31
7
- data.tar.gz: 74fbf160e046e0af706330d3a8912360b5a80c3ddf2dd5c671207e9c26ad4aec74f9c5b969ac94425eca1c9a84eb2e4b521b632eb5c508c9935e39c869ace4ff
6
+ metadata.gz: 6c9629493aca786b02202ae61fb7435e0d61a2a8a886e4ff988175b9232b8f0ca10f31d7d548377c8b1ae74361c8a2c25a7634bdaf665885e2495fc1c2a5d935
7
+ data.tar.gz: f9aad33b2aed468c98435862c64c67c9e46428a5cd4eedb78ff0daf56720f8391e064b863ec526dc48ea999c736fcb8d8e986d086b5be84021f2e6551daef2f5
data/CHANGELOG.md CHANGED
@@ -13,4 +13,8 @@ v 0.1.0
13
13
 
14
14
  v 0.1.1
15
15
 
16
- - Fix bug where invalid error message would be returned
16
+ - Fix bug where invalid error message would be returned
17
+
18
+ v 0.1.2
19
+
20
+ - `:error_message` option
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("$", "`#{param.to_s}`").sub("#","`#{value.to_s}`") unless @block.call(param,value)
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(@value, v) }
111
- return validate_error unless validate_error.nil?
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.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."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-param
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Symer