lib/rails/auth/acl/resource.rb in rails-auth-2.1.4 vs lib/rails/auth/acl/resource.rb in rails-auth-2.2.0
- old
+ new
@@ -6,14 +6,14 @@
# Rules for a particular route
class Resource
attr_reader :http_methods, :path, :host, :matchers
# Valid HTTP methods
- HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS PATCH LINK UNLINK).freeze
+ HTTP_METHODS = %w[GET HEAD PUT POST DELETE OPTIONS PATCH LINK UNLINK].freeze
# Options allowed for resource matchers
- VALID_OPTIONS = %w(method path host).freeze
+ VALID_OPTIONS = %w[method path host].freeze
# @option :options [String] :method HTTP method allowed ("ALL" for all methods)
# @option :options [String] :path path to the resource (regex syntax allowed)
# @param [Hash] :matchers which matchers are used for this resource
#
@@ -44,10 +44,11 @@
#
# @return [String, nil] name of the matcher which matched, or nil if none matched
#
def match(env)
return nil unless match!(env)
+
name, = @matchers.find { |_name, matcher| matcher.match(env) }
name
end
# Match *only* the request method/path/host against the given Rack environment.
@@ -56,12 +57,13 @@
# @param [Hash] :env Rack environment
#
# @return [Boolean] method and path *only* match the given environment
#
def match!(env)
- return false unless @http_methods.include?(env["REQUEST_METHOD".freeze])
- return false unless @path =~ env["PATH_INFO".freeze]
- return false unless @host.nil? || @host =~ env["HTTP_HOST".freeze]
+ return false unless @http_methods.include?(env["REQUEST_METHOD"])
+ return false unless @path =~ env["PATH_INFO"]
+ return false unless @host.nil? || @host =~ env["HTTP_HOST"]
+
true
end
private