Module: Role
- Included in:
- Policy::Base
- Defined in:
- lib/pundit_roles/policy/role.rb,
lib/pundit_roles/policy/role/option_builder.rb
Overview
Extended by Policy::Base. Defines the methods necessary for declaring roles.
Defined Under Namespace
Classes: OptionBuilder
Instance Attribute Summary collapse
-
#permissions ⇒ Object
Returns the value of attribute permissions.
-
#role_associations ⇒ Object
Returns the value of attribute role_associations.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
Instance Method Summary collapse
-
#role(*opts) ⇒ Object
Builds a new role by saving it into the #permissions class instance variable Valid options are :attributes, :associations, :associated_as, :scope.
Instance Attribute Details
#permissions ⇒ Object
Returns the value of attribute permissions.
5 6 7 |
# File 'lib/pundit_roles/policy/role.rb', line 5 def @permissions end |
#role_associations ⇒ Object
Returns the value of attribute role_associations.
6 7 8 |
# File 'lib/pundit_roles/policy/role.rb', line 6 def role_associations @role_associations end |
#scopes ⇒ Object
Returns the value of attribute scopes.
7 8 9 |
# File 'lib/pundit_roles/policy/role.rb', line 7 def scopes @scopes end |
Instance Method Details
#role(*opts) ⇒ Object
Builds a new role by saving it into the #permissions class instance variable Valid options are :attributes, :associations, :associated_as, :scope
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pundit_roles/policy/role.rb', line 14 def role(*opts) role_opts = opts..dup = role_opts.slice(*_role_default_keys) raise ArgumentError, 'Please provide at least one role' unless opts.present? () @permissions = {} if @permissions.nil? @scopes = {} if @scopes.nil? @role_associations = {} if @role_associations.nil? opts.each do |role| raise ArgumentError, "Expected Symbol for #{role}, got #{role.class}" unless role.is_a? Symbol if [:associated_as].present? build_associated_roles(role, [:associated_as]) end @permissions[role] = OptionBuilder.new(self, [:attributes], [:associations], [:scope]).permitted @scopes[role] = [:scope] end end |