Module: Ratify

Defined in:
lib/ratify.rb,
lib/ratify/version.rb

Overview

Provides permissions to any object that it is included in.

Examples:

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =

The gem’s semantic version.

'0.2.1'

Instance Method Summary collapse

Instance Method Details

#permits?(object, *actions) ⇒ true | false

Checks the permissions on an instance level.

Parameters:

  • object (Object)

    The object requesting the action(s).

  • actions (*Symbol)

    The actions being requested.

Returns:

  • (true | false)

    Whether or not the obejct is permitted.



69
70
71
# File 'lib/ratify.rb', line 69

def permits?(object, *actions)
  self.class.permits?(object, *actions, scope: self)
end