39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/checken/extensions/action_controller.rb', line 39
def restrict(permission_path, object_or_options = {}, options_if_object_provided = {})
if object_or_options.is_a?(Hash)
object = nil
options = object_or_options
else
object = object_or_options
options = options_if_object_provided
end
restrict_options = options.delete(:restrict_options) || {}
restrict_options[:strict] = options.delete(:strict) { true }
before_action(options) do
if object.is_a?(Proc)
resolved_object = object.call
elsif object.is_a?(Symbol)
if object.to_s =~ /\A@/
resolved_object = instance_variable_get(object.to_s)
else
resolved_object = send(object)
end
else
resolved_object = nil
end
restrict(permission_path, resolved_object, restrict_options)
end
end
|