Class: Lanes::Access::RoleCollection
- Inherits:
-
Object
- Object
- Lanes::Access::RoleCollection
- Includes:
- Enumerable
- Defined in:
- lib/lanes/access/role_collection.rb
Instance Method Summary collapse
-
#can_delete?(model, id) ⇒ Boolean
Can the User delete the model?.
-
#can_read?(model, attribute = nil) ⇒ Boolean
Can the User view the model?.
-
#can_write?(model, attribute = nil) ⇒ Boolean
Can the User create and update the model?.
- #each ⇒ Object
- #exposed_data ⇒ Object
-
#initialize(user) ⇒ RoleCollection
constructor
A new instance of RoleCollection.
-
#to_sym ⇒ Array<symbol>
List of roles.
Constructor Details
#initialize(user) ⇒ RoleCollection
Returns a new instance of RoleCollection.
7 8 9 10 11 |
# File 'lib/lanes/access/role_collection.rb', line 7 def initialize(user) @roles ||= user.role_names.map{ |name| "Lanes::Access::Roles::#{name.classify}".safe_constantize }.compact.map{ |klass| klass.new(user) } end |
Instance Method Details
#can_delete?(model, id) ⇒ Boolean
Returns Can the User delete the model?.
36 37 38 39 |
# File 'lib/lanes/access/role_collection.rb', line 36 def can_delete?(model,id) klass=model_to_class(model) @roles.each{ |role| role.can_delete?(klass) } end |
#can_read?(model, attribute = nil) ⇒ Boolean
Returns Can the User view the model?.
20 21 22 23 |
# File 'lib/lanes/access/role_collection.rb', line 20 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
Returns Can the User create and update the model?.
28 29 30 31 |
# File 'lib/lanes/access/role_collection.rb', line 28 def can_write?(model, attribute = nil) klass=model_to_class(model) test_access(klass, attribute, :write){ |role| role.can_write?(klass) } end |
#each ⇒ Object
46 47 48 |
# File 'lib/lanes/access/role_collection.rb', line 46 def each @roles.each{|r| yield r} end |
#exposed_data ⇒ Object
13 14 15 |
# File 'lib/lanes/access/role_collection.rb', line 13 def exposed_data @roles.map{ |role| role.class.to_s.demodulize.downcase } end |
#to_sym ⇒ Array<symbol>
Returns list of roles.
42 43 44 |
# File 'lib/lanes/access/role_collection.rb', line 42 def to_sym @roles.map{ |r| r.class.to_s.demodulize.downcase.to_sym } end |