Class: PrivatePerson::Permission

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/private_person/models/permission.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blockedObject



28
29
30
# File 'lib/private_person/models/permission.rb', line 28

def self.blocked
  where('NOT(relationship_type IN (?))', self.permissible_types)
end

.by_permissible(permissible) ⇒ Object



10
11
12
# File 'lib/private_person/models/permission.rb', line 10

def self.by_permissible(permissible)
  where("permissible_type = ? AND permissible_id = ?", permissible.class.name, permissible.id)
end

.by_permissor(permissor) ⇒ Object



6
7
8
# File 'lib/private_person/models/permission.rb', line 6

def self.by_permissor(permissor)
  where("permissor_type = ? AND permissor_id = ?", permissor.class.name, permissor.id)
end

.by_relationship_type(relationship_type) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/private_person/models/permission.rb', line 18

def self.by_relationship_type(relationship_type)
  if relationship_type == 'public' or relationship_type.nil?
    return where("relationship_type = 'public'")
  end
  if self.permissible_types.include? relationship_type
    return where("relationship_type = ? OR relationship_type = 'public'", relationship_type)
  end
  return where(0)
end

.by_wildcard(permissible_type) ⇒ Object



14
15
16
# File 'lib/private_person/models/permission.rb', line 14

def self.by_wildcard(permissible_type)
  where(:permissible_type => permissible_type, :permissible_id => nil)
end

.legitimateObject



32
33
34
# File 'lib/private_person/models/permission.rb', line 32

def self.legitimate
  where('relationship_type IN (?)', self.permissible_types)
end

.permissible_typesObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/private_person/models/permission.rb', line 36

def self.permissible_types
  permissible_types = ['public']
  for record in self.group('permissor_type').group('permissor_id')
    permissor = record.permissor_type.constantize.find(record.permissor_id)
    unless permissor.nil?
      for method in permissor.class.of
        permissible_types << method.to_s
      end
    end
  end
  permissible_types.compact
end

Instance Method Details

#existing_typesObject



49
50
51
52
53
54
55
# File 'lib/private_person/models/permission.rb', line 49

def existing_types
  existing_types = ['public']
  for method in permissor.class.of
    existing_types << method.to_s
  end
  existing_types
end