class Minican::Policy

Public Class Methods

new(object) click to toggle source

Creates a new instance of policy with object that is accessible via {object} or after the name of the policy class

@param [object] The object the policy tests against

# File lib/minican/policy.rb, line 10
def initialize(object)
  instance_variable_set(instance_name, object)
end

Public Instance Methods

can?(method, user) click to toggle source

Convenience method to call predicate method and return the value

@param [method] Method to call @param [user] User to send to the method

@return [Boolean]

# File lib/minican/policy.rb, line 21
def can?(method, user)
  send("#{method}?", user)
end
cannot?(method, user) click to toggle source

Convenience method to call predicate method and return the negated value

@param [method] Method to call @param [user] User to send to the method

@return [Boolean]

# File lib/minican/policy.rb, line 32
def cannot?(method, user)
  !can?(method, user)
end
object() click to toggle source

Conveneince method to get the current object without having to get the class name

# File lib/minican/policy.rb, line 38
def object
  instance_variable_get(instance_name)
end

Private Instance Methods

instance_name() click to toggle source
# File lib/minican/policy.rb, line 44
def instance_name
  class_name = self.class.to_s.gsub(/Policy$/, '')
  "@#{class_name.underscore}"
end