Module: Maybee::AuthorizationObject
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/maybee/authorization_object.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #allow?(access, subject = authorization_subject) ⇒ Boolean
- #authorize?(access, subject = authorization_subject) ⇒ Boolean
Instance Method Details
#allow?(access, subject = authorization_subject) ⇒ Boolean
39 40 41 42 |
# File 'lib/maybee/authorization_object.rb', line 39 def allow?(access, subject = ) = self.class.[access] or return(false) .any? { || .granted?(self, subject) } end |
#authorize?(access, subject = authorization_subject) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/maybee/authorization_object.rb', line 44 def (access, 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 |