Module: Permissify::Model

Included in:
Product, Role
Defined in:
lib/permissify/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/permissify/model.rb', line 3

def from
  @from
end

#from_permissions_modelObject

Returns the value of attribute from_permissions_model.



3
4
5
# File 'lib/permissify/model.rb', line 3

def from_permissions_model
  @from_permissions_model
end

Instance Method Details

#allows?(ability_key) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/permissify/model.rb', line 13

def allows?(ability_key)
  allowed = self.permissions[ability_key];
  # allowed && allowed['0']
  allowed && (allowed['0'] == '1') 
end

#establish_from_permissions_modelObject



5
6
7
# File 'lib/permissify/model.rb', line 5

def establish_from_permissions_model
  self.from_permissions_model ||= self.from.nil? ? nil : self.class.find(self.from)
end

#initialize_permissionsObject



9
10
11
# File 'lib/permissify/model.rb', line 9

def initialize_permissions
  self.permissions ||= self.from.nil? ? {} : establish_from_permissions_model.permissions
end

#remove_permissions(keys) ⇒ Object



19
20
21
22
23
# File 'lib/permissify/model.rb', line 19

def remove_permissions(keys)
  keys = [keys] if keys.class != Array
  keys.each{ |k| self.permissions[k] = nil}
  self.save
end

#underscored_name_symbolObject



30
31
32
# File 'lib/permissify/model.rb', line 30

def underscored_name_symbol
  self.class.underscored_name_symbol(self.name)
end

#update_permissions(new_or_updated_permissions) ⇒ Object



25
26
27
28
# File 'lib/permissify/model.rb', line 25

def update_permissions(new_or_updated_permissions)
  self.permissions = self.permissions.merge(new_or_updated_permissions)
  self.save
end