Method: CORS::Rules#required
- Defined in:
- lib/cors/rules.rb
#required(name, constraints = nil) {|value| ... } ⇒ Hash
Declare a required rule; the value must be present, and it must match the given constraints or block matcher.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cors/rules.rb', line 74 def required(name, constraints = nil, &block) matcher = if block_given? then block elsif constraints.is_a?(Regexp) constraints.method(:===) elsif constraints.is_a?(String) constraints.method(:===) elsif constraints.is_a?(Array) constraints.method(:include?) else raise ArgumentError, "unknown matcher #{(constraints || block).inspect}" end { name: name, matcher: matcher, required: true }.tap do |rule| @rules << rule @rules_map[name] << rule end end |