class ChronosAuthz::ACL::Record

Constants

VALID_HTTP_METHODS

Public Class Methods

new(value = {}) click to toggle source
Calls superclass method
# File lib/chronos_authz/acl.rb, line 46
def initialize(value = {})
  value = value.with_indifferent_access
  value[:http_method] = normalize_http_methods(value[:http_method])
  value[:path] = normalize_path(value[:path])

  super(value)
  validate!
end

Public Instance Methods

matches?(http_method, request_path) click to toggle source
# File lib/chronos_authz/acl.rb, line 55
def matches?(http_method, request_path)
  return false if request_path.nil?
  
  request_path = normalize_path(request_path)
  path_pattern = /\A#{self.path}\z/

  method_matched = self.http_method.empty? || self.http_method.include?(http_method.to_s.upcase)

  return false if !method_matched
  return !request_path.match(path_pattern).nil?
end

Private Instance Methods

normalize_http_methods(http_methods) click to toggle source
# File lib/chronos_authz/acl.rb, line 73
def normalize_http_methods(http_methods)
  http_methods = [http_methods] if !http_methods.is_a? Array
  http_methods.map!{ |http_method| http_method.to_s.upcase }

  return http_methods.reject { |http_method| http_method.blank? }
end
normalize_path(resource_path) click to toggle source
# File lib/chronos_authz/acl.rb, line 69
def normalize_path(resource_path)
  return resource_path.squish if !resource_path.nil?
end