Module: PolicyHelper

Defined in:
app/helpers/policy_helper.rb

Constant Summary collapse

PERMISSION_ALIASES =
{
  list: :index
}.with_indifferent_access.freeze

Instance Method Summary collapse

Instance Method Details

#can?(*actions) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'app/helpers/policy_helper.rb', line 6

def can?(*actions)
  model = actions.pop.to_s
  permissions = policy(model.singularize.classify.constantize)
  actions.all? { |action| permissions.send(map_policy_permission(action)) }
end

#map_policy_permission(action) ⇒ Object



12
13
14
# File 'app/helpers/policy_helper.rb', line 12

def map_policy_permission(action)
  "#{(PERMISSION_ALIASES[action] || action)}?"
end