module Regulator
Constants
- SUFFIX
- VERSION
Public Class Methods
policy(user, record, controller_or_namespace = nil)
click to toggle source
# File lib/regulator.rb, line 57 def policy(user, record, controller_or_namespace = nil) policy = PolicyFinder.new(record,controller_or_namespace).policy policy.new(user, record) if policy end
policy!(user, record, controller_or_namespace = nil)
click to toggle source
# File lib/regulator.rb, line 62 def policy!(user, record, controller_or_namespace = nil) PolicyFinder.new(record,controller_or_namespace).policy!.new(user, record) end
policy_namespace()
click to toggle source
# File lib/regulator.rb, line 74 def self.policy_namespace ( self.parent != Object ? self.parent : nil ) end
policy_scope(user, scope, controller_or_namespace = nil)
click to toggle source
# File lib/regulator.rb, line 48 def policy_scope(user, scope, controller_or_namespace = nil) policy_scope = PolicyFinder.new(scope,controller_or_namespace).scope policy_scope.new(user, scope).resolve if policy_scope end
policy_scope!(user, scope, controller_or_namespace = nil)
click to toggle source
# File lib/regulator.rb, line 53 def policy_scope!(user, scope, controller_or_namespace = nil) PolicyFinder.new(scope,controller_or_namespace).scope!.new(user, scope).resolve end
Public Instance Methods
permitted_attributes(record)
click to toggle source
# File lib/regulator.rb, line 152 def permitted_attributes(record) name = record.class.to_s.demodulize.underscore params.require(name).permit(*policy(record).permitted_attributes) end
policies()
click to toggle source
# File lib/regulator.rb, line 157 def policies @_regulator_policies ||= {} end
policy(record)
click to toggle source
# File lib/regulator.rb, line 148 def policy(record) policies[record] ||= Regulator.policy!(regulator_user, record, self) end
policy_namespace()
click to toggle source
# File lib/regulator.rb, line 78 def policy_namespace @_policy_namespace ||= self.class.policy_namespace end
policy_scope(scope)
click to toggle source
# File lib/regulator.rb, line 143 def policy_scope(scope) @_regulator_policy_scoped = true regulator_policy_scope(scope) end
policy_scopes()
click to toggle source
# File lib/regulator.rb, line 161 def policy_scopes @_regulator_policy_scopes ||= {} end
regulator_policy_scoped?()
click to toggle source
# File lib/regulator.rb, line 110 def regulator_policy_scoped? !!@_regulator_policy_scoped end
regulator_user()
click to toggle source
# File lib/regulator.rb, line 165 def regulator_user current_user end
skip_policy_scope()
click to toggle source
# File lib/regulator.rb, line 139 def skip_policy_scope @_regulator_policy_scoped = true end
verify_policy_scoped()
click to toggle source
# File lib/regulator.rb, line 118 def verify_policy_scoped raise PolicyScopingNotPerformedError unless regulator_policy_scoped? end
Private Instance Methods
regulator_policy_scope(scope)
click to toggle source
# File lib/regulator.rb, line 170 def regulator_policy_scope(scope) policy_scopes[scope] ||= Regulator.policy_scope!(regulator_user, scope, self) end