Class: Lawkeeper::PolicyLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/lawkeeper.rb

Class Method Summary collapse

Class Method Details

.[](model) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lawkeeper.rb', line 37

def self.[](model)
  klass = model.is_a?(Class) ? model : model.class

  if klass.respond_to?(:policy_class)
    klass.policy_class
  else
    begin
      Object.const_get("#{klass}Policy")
    rescue NameError
      raise NotDefined
    end
  end
end

.for_scope(scope) ⇒ Object



51
52
53
54
# File 'lib/lawkeeper.rb', line 51

def self.for_scope(scope)
  model_name = Lawkeeper.scope_finder.call(scope)
  self[Object.const_get(model_name)]
end