module AuthorizationNext::Identity::UserExtensions::InstanceMethods
Public Instance Methods
method_missing( method_sym, *args )
click to toggle source
Calls superclass method
# File lib/authorization_next/publishare/identity.rb, line 21 def method_missing( method_sym, *args ) method_name = method_sym.to_s authorizable_object = args.empty? ? nil : args[0] base_regex = "is_(\\w+)" fancy_regex = base_regex + "_(#{AuthorizationNext::Base::VALID_PREPOSITIONS_PATTERN})" is_either_regex = '^((' + fancy_regex + ')|(' + base_regex + '))' base_not_regex = "is_no[t]?_(\\w+)" fancy_not_regex = base_not_regex + "_(#{AuthorizationNext::Base::VALID_PREPOSITIONS_PATTERN})" is_not_either_regex = '^((' + fancy_not_regex + ')|(' + base_not_regex + '))' if method_name =~ Regexp.new(is_either_regex + '_what$') role_name = $3 || $6 has_role_for_objects(role_name) elsif method_name =~ Regexp.new(is_not_either_regex + '\?$') role_name = $3 || $6 not is_role?( role_name, authorizable_object ) elsif method_name =~ Regexp.new(is_either_regex + '\?$') role_name = $3 || $6 is_role?( role_name, authorizable_object ) elsif method_name =~ Regexp.new(is_not_either_regex + '$') role_name = $3 || $6 is_no_role( role_name, authorizable_object ) elsif method_name =~ Regexp.new(is_either_regex + '$') role_name = $3 || $6 is_role( role_name, authorizable_object ) else super end end
Private Instance Methods
has_role_for_objects(role_name)
click to toggle source
# File lib/authorization_next/publishare/identity.rb, line 79 def has_role_for_objects(role_name) roles = self.roles.find_all_by_name( role_name ) roles.collect do |role| if role.authorizable_id.nil? role.authorizable_type.nil? ? nil : Module.const_get( role.authorizable_type ) # Returns class else role.authorizable end end end
is_no_role( role_name, authorizable_object = nil )
click to toggle source
# File lib/authorization_next/publishare/identity.rb, line 63 def is_no_role( role_name, authorizable_object = nil ) if authorizable_object.nil? self.has_no_role role_name else self.has_no_role role_name, authorizable_object end end
is_role( role_name, authorizable_object = nil )
click to toggle source
# File lib/authorization_next/publishare/identity.rb, line 71 def is_role( role_name, authorizable_object = nil ) if authorizable_object.nil? self.has_role role_name else self.has_role role_name, authorizable_object end end
is_role?( role_name, authorizable_object )
click to toggle source
# File lib/authorization_next/publishare/identity.rb, line 54 def is_role?( role_name, authorizable_object ) if authorizable_object.nil? return self.has_role?(role_name) elsif authorizable_object.respond_to?(:accepts_role?) return self.has_role?(role_name, authorizable_object) end false end