module Ratify

Provides permissions to any object that it is included in.

@example Basic usage

class User
  attr_accessor :role
end

class Record
  include Ratify

  permit User, :create, if: -> { role == :admin }
end

user = User.new
Record.permit?(user, :create) # => false

user.role = :admin
Record.permit?(user, :create) # => true

Constants

VERSION

The gem's semantic version.

Public Class Methods

included(klass) click to toggle source

Called when the object is included in a class.

@!visibility private @param [Class] klass The class {Ratify} is being included in. @return [void]

# File lib/ratify.rb, line 60
def self.included(klass)
  klass.extend(Ratify::ClassMethods)
end

Public Instance Methods

permits?(object, *actions) click to toggle source

Checks the permissions on an instance level.

@param [Object] object The object requesting the action(s). @param [*Symbol] actions The actions being requested. @return [true | false] Whether or not the obejct is permitted.

# File lib/ratify.rb, line 69
def permits?(object, *actions)
  self.class.permits?(object, *actions, scope: self)
end