Module: Canhaz::Mongoid::ObjectExtensions

Defined in:
lib/mongoid-canhaz/object_extensions.rb

Instance Method Summary collapse

Instance Method Details

#canhaz_object?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/mongoid-canhaz/object_extensions.rb', line 5

def canhaz_object?
  true
end

#subjects_with_permission(type, permission) ⇒ Object

Gets the subjects that have the corresponding permission and type on this model

Parameters:

  • type (Class)

    The type of the subjects we’re looking for

  • permission (String, Symbol)

    The permission

Raises:



13
14
15
16
17
# File 'lib/mongoid-canhaz/object_extensions.rb', line 13

def subjects_with_permission(type, permission)
  raise Exceptions::NotACanHazSubject unless type.respond_to?(:acts_as_canhaz_subject)
  permissions = self.permissions_subjects.where(:type => self.class.to_s, :permission => permission.to_s)
  type.in(:id => permissions.collect(&:csubject_id))
end