Module: Caber::Object

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/caber/object.rb

Instance Method Summary collapse

Instance Method Details

#grant_permission_to(permission, subject) ⇒ Object



20
21
22
23
24
# File 'app/models/concerns/caber/object.rb', line 20

def grant_permission_to(permission, subject)
  rel = Caber::Relation.find_or_initialize_by(subject: subject, object: self)
  rel.permission = permission
  rel.save!
end

#grants_permission_to?(permission, subject) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/concerns/caber/object.rb', line 26

def grants_permission_to?(permission, subject)
  Caber::Relation.where(object: self, subject: [subject, nil], permission: permission).present?
end

#revoke_all_permissions(subject) ⇒ Object



34
35
36
# File 'app/models/concerns/caber/object.rb', line 34

def revoke_all_permissions(subject)
  Caber::Relation.where(object: self, subject: subject).destroy_all
end

#revoke_permission(permission, subject) ⇒ Object



30
31
32
# File 'app/models/concerns/caber/object.rb', line 30

def revoke_permission(permission, subject)
  Caber::Relation.where(object: self, subject: subject, permission: permission).destroy_all
end