class Sand::PolicyFinder
Constants
- POLICY_SUFFIX
Public Class Methods
new(object)
click to toggle source
# File lib/sand/policy_finder.rb, line 5 def initialize(object) @object = object end
Public Instance Methods
policy!()
click to toggle source
# File lib/sand/policy_finder.rb, line 15 def policy! klass = find klass = Util.constantize(klass) if klass.is_a?(String) klass rescue NameError raise NotDefinedError end
scope!()
click to toggle source
# File lib/sand/policy_finder.rb, line 9 def scope! policy!::Scope rescue NameError raise NotDefinedError end
Private Instance Methods
find()
click to toggle source
rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/LineLength
# File lib/sand/policy_finder.rb, line 26 def find klass = @object return klass if @object.nil? if @object.respond_to?(:sand_policy) @object.sand_policy elsif @object.class.respond_to?(:sand_policy) @object.sand_policy else klass = if @object.is_a?(Symbol) @object.to_s.camelize elsif @object.respond_to?(:model) @object.model elsif @object.respond_to?(:model_class) @object.model_class else @object.to_s end "#{klass}#{POLICY_SUFFIX}" end end