Class: Role::OptionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pundit_roles/policy/role/option_builder.rb

Overview

Helper class, which handles building of a role’s #permissions_hash.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policy, attr_opts, assoc_opts, scope) ⇒ OptionBuilder

Returns a new instance of OptionBuilder.



13
14
15
16
17
18
19
# File 'lib/pundit_roles/policy/role/option_builder.rb', line 13

def initialize(policy, attr_opts, assoc_opts, scope)
  @policy = policy
  @attr_opts = attr_opts
  @assoc_opts = assoc_opts
  @scope = scope
  freeze
end

Instance Attribute Details

#policyObject (readonly)

Returns the value of attribute policy.



11
12
13
# File 'lib/pundit_roles/policy/role/option_builder.rb', line 11

def policy
  @policy
end

Instance Method Details

#permittedObject

Returns a refined hash of attributes and associations the current_user has access to



22
23
24
25
26
27
# File 'lib/pundit_roles/policy/role/option_builder.rb', line 22

def permitted
  return {
    attributes: permitted_options(@attr_opts, 'attributes'),
    associations: permitted_options(@assoc_opts, 'associations')
  }
end