Class: Rack::Parameter::Rule
- Inherits:
-
Object
- Object
- Rack::Parameter::Rule
- Defined in:
- lib/rack/param.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, &block) ⇒ Rule
constructor
A new instance of Rule.
- #validate(param, value, error_msg = nil) ⇒ Object
Constructor Details
#initialize(message, &block) ⇒ Rule
Returns a new instance of Rule.
47 48 49 50 |
# File 'lib/rack/param.rb', line 47 def initialize , &block @block = block @message = end |
Class Method Details
.rule(message, &block) ⇒ Object
52 53 54 |
# File 'lib/rack/param.rb', line 52 def self.rule , &block new , &block end |
Instance Method Details
#validate(param, value, error_msg = nil) ⇒ Object
56 57 58 |
# File 'lib/rack/param.rb', line 56 def validate param, value, error_msg=nil return (error_msg || @message).sub('$',"`#{param.to_s}`").sub('#',"`#{value.to_s}`") unless @block.call(param,value) end |