Module: Authorizable::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/authorizable/model.rb

Overview

this should be included on the ‘User’ model or whatever is going to be performing action that need to be authorized

Constant Summary collapse

IS_OWNER =
0
IS_UNRELATED =
1

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/authorizable/model.rb', line 12

def method_missing(name, *args, &block)
  string_name = name.to_s

  if string_name =~ /can_(.+)\?/
    permission_name = $1
    permission_name.gsub!('destroy', 'delete')
    if ["delete", "edit", "create"].include?(permission_name)
      # shorthand for delete_{object_name}
      object = args[0]
      object_name = object.class.name.downcase
      return send("can_#{permission_name}_#{object_name}?", *args, &block)
    else
      return process_permission(name, permission_name, args)
    end
  else
    super(name, *args, &block)
  end
end