class Ingress::PermissionRule
Attributes
action[R]
conditions[R]
subject[R]
Public Class Methods
new(allows:, action:, subject:, conditions: nil)
click to toggle source
# File lib/ingress/permission_rule.rb, line 5 def initialize(allows:, action:, subject:, conditions: nil) @allows = allows @action = action @subject = subject @conditions = conditions end
Public Instance Methods
allows?()
click to toggle source
# File lib/ingress/permission_rule.rb, line 12 def allows? @allows end
match?(given_action, given_subject, user, options = {})
click to toggle source
# File lib/ingress/permission_rule.rb, line 16 def match?(given_action, given_subject, user, options = {}) return false unless action_matches?(given_action) return false unless subject_matches?(given_subject) conditions_match?(user, given_subject, options) end
Private Instance Methods
action_matches?(given_action)
click to toggle source
# File lib/ingress/permission_rule.rb, line 25 def action_matches?(given_action) given_action == action || given_action == "*" || "*" == action end
conditions_match?(user, given_subject, options)
click to toggle source
# File lib/ingress/permission_rule.rb, line 38 def conditions_match?(user, given_subject, options) conditions.all? do |condition| if condition.arity == 2 condition.call(user, given_subject) else condition.call(user, given_subject, options) end end rescue => e log_error(e) false end
log_error(error)
click to toggle source
# File lib/ingress/permission_rule.rb, line 51 def log_error(error) if defined?(Rails) Rails.logger.error error.message Rails.logger.error error.backtrace.join("\n") else $stderr.puts error.message $stderr.puts error.backtrace.join("\n") end end
subject_matches?(given_subject)
click to toggle source
# File lib/ingress/permission_rule.rb, line 31 def subject_matches?(given_subject) given_subject == subject || given_subject.class == subject || given_subject == "*" || "*" == subject end