Module: PrivatePerson::ActsAsPermissor::InstanceMethods

Defined in:
lib/private_person/extensions/acts_as_permissor.rb

Instance Method Summary collapse

Instance Method Details

#permission_params(whom, what) ⇒ Object


42
43
44
45
46
47
48
# File 'lib/private_person/extensions/acts_as_permissor.rb', line 42

def permission_params(whom, what)
  ::ActionController::Parameters.new({
    :relationship_type => whom, 
    :permissible_type => what.class.name, 
    :permissible_id => what.id
  }).permit!
end

#permit!(whom, what) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/private_person/extensions/acts_as_permissor.rb', line 24

def permit!(whom, what)
  existing = self.permissions_as_permissor.by_relationship_type(whom).by_permissible(what)

  if existing.empty?
    self.permissions_as_permissor.create!(permission_params(whom, what))
  end
  self.permissions_as_permissor.reload
end

#wildcard_permission_params(whom, what) ⇒ Object


50
51
52
53
54
55
# File 'lib/private_person/extensions/acts_as_permissor.rb', line 50

def wildcard_permission_params(whom, what)
  ::ActionController::Parameters.new({
    :relationship_type => whom, 
    :permissible_type => what
  }).permit!
end

#wildcard_permit!(whom, what) ⇒ Object


33
34
35
36
37
38
39
40
# File 'lib/private_person/extensions/acts_as_permissor.rb', line 33

def wildcard_permit!(whom, what)
  existing = self.permissions_as_permissor.by_relationship_type(whom).where(:permissible_type, what)

  # if existing.empty?
    self.permissions_as_permissor.create!(wildcard_permission_params(whom, what))
  # end
  self.permissions_as_permissor.reload
end