Class: Object

Inherits:
BasicObject
Defined in:
lib/clean-policy/global.rb

Overview

“smart” access that will fill current user if possible fell free to overwrite this method

Instance Method Summary collapse

Instance Method Details

#policy(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clean-policy/global.rb', line 26

def policy *args
  opts = args.first.dup

  unless opts.is_a?(Hash)
    opts = { model: opts }
    opts.merge! args[1] if args[1]
  end

  opts[:user] ||= user_current if respond_to?(:user_current)
  opts[:user] ||= User.current if defined?(User) && User.respond_to?(:current)

  Policy opts
end