Class: Accessly::Permission::Revoke

Inherits:
Base
  • Object
show all
Defined in:
lib/accessly/permission/revoke.rb

Instance Method Summary collapse

Methods inherited from Base

#on_segment

Constructor Details

#initialize(actor) ⇒ Revoke

Create an instance of Accessly::Permission::Revoke Pass in an ActiveRecord::Base for actor

Parameters:

  • actor (ActiveRecord::Base)

    The actor to revoke permission



9
10
11
12
13
14
15
16
17
# File 'lib/accessly/permission/revoke.rb', line 9

def initialize(actor)
  super(actor)
  @actor = case actor
  when ActiveRecord::Base
    actor
  else
    raise Accessly::RevokeError.new("Actor is not an ActiveRecord::Base object")
  end
end

Instance Method Details

#revoke!(action_id, object_type) ⇒ nil #revoke!(action_id, object_type, object_id) ⇒ nil

Revoke a permission for an actor.

Overloads:

  • #revoke!(action_id, object_type) ⇒ nil

    Revoke permission on a general action in the given namespace represented by object_type.

    Examples:

    # Remove user access to posts for action id 3
    Accessly::Permission::Revoke.new(user).revoke!(3, Post)
    # Remove user access to posts for action id 3 on a segment
    Accessly::Permission::Revoke.new(user).on_segment(1).revoke!(3, Post)

    Parameters:

    • action_id (Integer)

      The action to revoke

    • object_type (String)

      The namespace of the given action_id.

    Returns:

    • (nil)

      Returns nil if successful

    Raises:

  • #revoke!(action_id, object_type, object_id) ⇒ nil

    Revoke permission on an ActiveRecord object.

    Examples:

    # Remove user access to Post 7 for action id 3
    Accessly::Permission::Revoke.new(user).revoke!(3, Post, 7)
    # Remove user access to Post 7 for action id 3 on a segment
    Accessly::Permission::Revoke.new(user).on_segment(1).revoke!(3, Post, 7)

    Parameters:

    • action_id (Integer)

      The action to revoke

    • object_type (ActiveRecord::Base)

      The ActiveRecord model that removes a permission.

    • object_id (Integer)

      The id of the ActiveRecord object that removes a permission

    Returns:

    • (nil)

      Returns nil if successful

    Raises:

Returns:

  • (nil)


51
52
53
54
55
56
57
# File 'lib/accessly/permission/revoke.rb', line 51

def revoke!(action_id, object_type, object_id = nil)
  if object_id.nil?
    general_action_revoke(action_id, object_type)
  else
    object_action_revoke(action_id, object_type, object_id)
  end
end