Class: Hippo::Access::RoleCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hippo/access/role_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ RoleCollection


7
8
9
10
11
12
13
# File 'lib/hippo/access/role_collection.rb', line 7

def initialize(user)
    @role_names = user.role_names.clone
    @role_names << 'basic_user'
    @roles = @role_names.map{ |name|
        "Hippo::Access::Roles::#{name.classify}".safe_constantize
    }.compact.map{ |klass| klass.new(user) }
end

Instance Method Details

#can_delete?(model, id) ⇒ Boolean


44
45
46
47
# File 'lib/hippo/access/role_collection.rb', line 44

def can_delete?(model,id)
    klass=model_to_class(model)
    @roles.each{ |role| role.can_delete?(klass) }
end

#can_read?(model, attribute = nil) ⇒ Boolean


28
29
30
31
# File 'lib/hippo/access/role_collection.rb', line 28

def can_read?(model, attribute = nil)
    klass=model_to_class(model)
    test_access(klass, attribute, :read){ |role| role.can_read?(klass) }
end

#can_write?(model, attribute = nil) ⇒ Boolean


36
37
38
39
# File 'lib/hippo/access/role_collection.rb', line 36

def can_write?(model, attribute = nil)
    klass=model_to_class(model)
    test_access(klass, attribute, :write){ |role| role.can_write?(klass) }
end

#eachObject


54
55
56
# File 'lib/hippo/access/role_collection.rb', line 54

def each
    @roles.each{|r| yield r}
end

#exposed_dataObject


15
16
17
# File 'lib/hippo/access/role_collection.rb', line 15

def exposed_data
    @role_names
end

#include?(role) ⇒ Boolean


21
22
23
# File 'lib/hippo/access/role_collection.rb', line 21

def include?(role)
    @role_names.include?(role)
end

#to_symArray<symbol>


50
51
52
# File 'lib/hippo/access/role_collection.rb', line 50

def to_sym
    @roles.map{ |r| r.class.to_s.demodulize.downcase.to_sym }
end