Class: Formol::Permissions::Profiles

Inherits:
Object
  • Object
show all
Defined in:
lib/formol/permissions/profiles.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProfiles

Returns a new instance of Profiles.



4
5
6
# File 'lib/formol/permissions/profiles.rb', line 4

def initialize
  @profiles = {}
end

Class Method Details

.from_hash(hash) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/formol/permissions/profiles.rb', line 8

def self.from_hash(hash)
  p = Profiles.new
  
  hash.each do |name, opts|
    p.add_profile(name, opts)
  end
  
  p
end

Instance Method Details

#[](name) ⇒ Object



39
40
41
# File 'lib/formol/permissions/profiles.rb', line 39

def [](name)
  @profiles[name.to_sym]
end

#add_profile(name, opts = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/formol/permissions/profiles.rb', line 30

def add_profile(name, opts = {})
  r = []

  r += self[opts[:extends]].rights if opts[:extends]
  r += opts[:rights] if opts[:rights]

  @profiles[name.to_sym] = Profile.new(name, r.uniq)
end

#add_right_to_profile(name, right) ⇒ Object



18
19
20
# File 'lib/formol/permissions/profiles.rb', line 18

def add_right_to_profile(name, right)
  @profiles[name.to_sym] << right.to_sym
end

#delete_right_from_profile(name, right) ⇒ Object



22
23
24
# File 'lib/formol/permissions/profiles.rb', line 22

def delete_right_from_profile(name, right)
  @profiles[name.to_sym].delete(right)
end

#profilesObject



26
27
28
# File 'lib/formol/permissions/profiles.rb', line 26

def profiles
  @profiles.keys
end