Class: Hippo::Access::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/hippo/access/role.rb

Constant Summary collapse

ALL =
Array.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Role

Returns a new instance of Role.


7
8
9
# File 'lib/hippo/access/role.rb', line 7

def initialize(user)
    @user = user
end

Class Method Details

.all_availableObject


73
74
75
# File 'lib/hippo/access/role.rb', line 73

def all_available
    ALL
end

.can_access_locked_roles?(roles) ⇒ Boolean

By default a role can only access if it's type is included in the array of acceptable roles. An Admin role may provide a custom implementation

Returns:

  • (Boolean)

79
80
81
# File 'lib/hippo/access/role.rb', line 79

def can_access_locked_roles?(roles)
    roles.include?(self)
end

.delete(*klasses) ⇒ Object


57
58
59
# File 'lib/hippo/access/role.rb', line 57

def delete(*klasses )
    delete_types.push(*klasses)
end

.grant(*klasses) ⇒ Object


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

def grant( *klasses )
    read_types.push(*klasses)
    write_types.push(*klasses)
    delete_types.push(*klasses)
end

.grant_global_access(types = :all, *klass) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hippo/access/role.rb', line 26

def grant_global_access(types=:all, *klass)
    unless types.is_a?(Symbol)
        klass.unshift(types)
        types=:all
    end
    types = [:read,:write,:delete] if :all == types
    types = [*types]
    ALL.each do | child |
        types.each{ |type| child.send(type).concat(klass) }
    end
end

.inherited(subklass) ⇒ Object


38
39
40
41
# File 'lib/hippo/access/role.rb', line 38

def inherited(subklass)
    ALL << subklass
    subklass.read_types = []; subklass.write_types = []; subklass.delete_types = []
end

.lock(klass, *attributes) ⇒ Object


61
62
63
64
65
# File 'lib/hippo/access/role.rb', line 61

def lock(klass, *attributes)
    attributes.each do | attr |
        LockedFields.lock(klass, attr, self)
    end
end

.lock_writes(klass, *attributes) ⇒ Object


67
68
69
70
71
# File 'lib/hippo/access/role.rb', line 67

def lock_writes(klass, *attributes)
    attributes.each do | attr |
        LockedFields.lock(klass, attr, self, :write)
    end
end

.read(*klasses) ⇒ Object


49
50
51
# File 'lib/hippo/access/role.rb', line 49

def read( *klasses )
    read_types.push(*klasses)
end

.write(*klasses) ⇒ Object


53
54
55
# File 'lib/hippo/access/role.rb', line 53

def write( *klasses )
    write_types.push(*klasses)
end

Instance Method Details

#can_delete?(model) ⇒ Boolean

Returns:

  • (Boolean)

19
20
21
# File 'lib/hippo/access/role.rb', line 19

def can_delete?(model)
    delete_types.include?(model)
end

#can_read?(model) ⇒ Boolean

Returns:

  • (Boolean)

11
12
13
# File 'lib/hippo/access/role.rb', line 11

def can_read?(model)
    read_types.include?(model)
end

#can_write?(model) ⇒ Boolean

Returns:

  • (Boolean)

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

def can_write?(model)
    write_types.include?(model)
end