Class: Faalis::Discovery::Permissions
- Inherits:
-
Object
- Object
- Faalis::Discovery::Permissions
- Defined in:
- lib/faalis/discovery/permissions.rb
Overview
This class is responsible to discoering all Permissions classes and provide a list of available permissions
Class Method Summary collapse
- .all_permissions ⇒ Object
-
.create_all_permissions ⇒ Object
Creating all possible permissions in database using ‘Faalis::Permission` model.
-
.permission_objects(&block) ⇒ Object
Run the given block for each object with permissions.
Class Method Details
.all_permissions ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/faalis/discovery/permissions.rb', line 27 def self. = [] do |object| .concat(object.(object)) end .uniq end |
.create_all_permissions ⇒ Object
Creating all possible permissions in database using ‘Faalis::Permission` model
38 39 40 41 42 43 44 45 46 |
# File 'lib/faalis/discovery/permissions.rb', line 38 def self. do |object| object..each do |perm| Faalis::Permission.where(model: object.to_s, permission_type: perm).first_or_create end end end |
.permission_objects(&block) ⇒ Object
Run the given block for each object with permissions
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/faalis/discovery/permissions.rb', line 8 def self.(&block) objects = [] # Walkthrough all models in application by using # model_discovery gem and check for `permission_strings` # method in models (If `Faalis::Permissions` included in # model it has the permission_strings). And concat the # permissions to `@permissions` instance method. ::ApplicationModels.to_adapter.find_all.each do |m| # `m` is a string contains name of a model and # we use contstantize to get the model class with # such name model = m.model.constantize if model.respond_to? :permission_strings block.call(model) end end end |