Class: Roleback::Configuration
- Inherits:
-
Object
- Object
- Roleback::Configuration
- Defined in:
- lib/roleback/configuration.rb
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#max_inheritance_depth ⇒ Object
readonly
Returns the value of attribute max_inheritance_depth.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #can?(role_name, scope: ::Roleback::ANY, resource: ::Roleback::ANY, action: ::Roleback::ANY) ⇒ Boolean
- #construct! ⇒ Object
- #find_role!(name) ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/roleback/configuration.rb', line 57 def initialize( = {}) @options = @roles = {} if [:max_inheritance_depth] @max_inheritance_depth = [:max_inheritance_depth] else @max_inheritance_depth = 10 end end |
Instance Attribute Details
#max_inheritance_depth ⇒ Object (readonly)
Returns the value of attribute max_inheritance_depth.
55 56 57 |
# File 'lib/roleback/configuration.rb', line 55 def max_inheritance_depth @max_inheritance_depth end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
54 55 56 |
# File 'lib/roleback/configuration.rb', line 54 def roles @roles end |
Instance Method Details
#can?(role_name, scope: ::Roleback::ANY, resource: ::Roleback::ANY, action: ::Roleback::ANY) ⇒ Boolean
74 75 76 77 |
# File 'lib/roleback/configuration.rb', line 74 def can?(role_name, scope: ::Roleback::ANY, resource: ::Roleback::ANY, action: ::Roleback::ANY) role = self.find_role!(role_name) role.can?(scope: scope, resource: resource, action: action) end |
#construct! ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/roleback/configuration.rb', line 79 def construct! # go through all roles and find their parents @roles.each do |name, role| parents = role.parents next unless parents && !parents.empty? found_parents = [] parents.each do |parent| found_parent = @roles[parent] raise ::Roleback::BadConfiguration, "Role #{parent} not found" unless found_parent found_parents << found_parent role.instance_variable_set(:@parents, found_parents) end end # go through all roles, and inherit their parents' rules @roles.each do |name, role| role.inherit end end |
#find_role!(name) ⇒ Object
68 69 70 71 72 |
# File 'lib/roleback/configuration.rb', line 68 def find_role!(name) role = self.roles[name.to_sym] raise ::Roleback::MissingRole, "Role #{name} not found" unless role role end |