module Maybee::AuthorizationObject

Public Instance Methods

allow?(access, subject = authorization_subject) click to toggle source
# File lib/maybee/authorization_object.rb, line 39
def allow?(access, subject = authorization_subject)
  authorizations = self.class.authorizations[access] or return(false)
  authorizations.any? { |authorization| authorization.granted?(self, subject) }
end
authorize?(access, subject = authorization_subject) click to toggle source
# File lib/maybee/authorization_object.rb, line 44
def authorize?(access, subject = authorization_subject)
  errors.clear
  return true if allow?(access, subject)
  defaults = (self.class.lookup_ancestors + [ActiveRecord::Base]).map do |klass|
    :"#{self.class.i18n_scope}.authorizations.#{klass.model_name.i18n_key}.#{access}"
  end
  key = defaults.shift
  errors.add(:base, :not_authorized, :access => I18n.translate(key, :default => defaults))
  false
end

Private Instance Methods

wrap_callback_result_with_terminator(result) click to toggle source

def with_authorization_to(access, object = self)

if authorization_user && authorization_user.may?(access, object)
  yield
else
  false
end

end

# File lib/maybee/authorization_object.rb, line 65
def wrap_callback_result_with_terminator(result)
  false == result ? throw(:abort) : result
end