Class: StraightJacket::Collection
- Inherits:
-
Object
- Object
- StraightJacket::Collection
- Defined in:
- lib/straight_jacket/collection.rb
Instance Method Summary collapse
-
#initialize(param, required = false, &block) ⇒ Collection
constructor
A new instance of Collection.
- #matches?(request) ⇒ Boolean
Constructor Details
#initialize(param, required = false, &block) ⇒ Collection
Returns a new instance of Collection.
4 5 6 7 8 |
# File 'lib/straight_jacket/collection.rb', line 4 def initialize(param, required = false, &block) @param = param @required = required @validator = block end |
Instance Method Details
#matches?(request) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/straight_jacket/collection.rb', line 10 def matches?(request) if request.parameters.has_key?(param) value = request.parameters[param] if value.respond_to?(:all?) value.all? do |value| validator.call(value) end else false end else !required end end |