Sha256: 82b1c3289083b15742826fe4faa45e8b3ac64e44b16ebfab02bd8524dfc9cd2b

Contents?: true

Size: 1017 Bytes

Versions: 1

Compression:

Stored size: 1017 Bytes

Contents

require "active_support/concern"
require "miau/version"
require "miau/error"
require "miau/storage"

module Miau
  extend ActiveSupport::Concern

  included do
    if respond_to?(:helper_method)
      helper_method :authorized?
      helper_method :miau_user
    end
  end

  def authorize!(resource = nil, hsh = {})
    @_miau_authorization_performed = true
    result = authorized?(resource, hsh)
    raise Miau::NotAuthorizedError unless result == true
  end

  def authorized?(resource = nil, hsh = {})
    klass = hsh[:class]
    klass ||= params[:controller].camelize
    action = hsh[:action]
    action ||= params[:action]
    Miau::PolicyStorage.instance.run(klass, action, miau_user, resource)
  end

  def miau_user
    current_user
  end

  def skip_authorization
    @_miau_authorization_performed = true
  end

  def verify_authorized
    raise AuthorizationNotPerformedError unless miau_authorization_performed?
  end

  def miau_authorization_performed?
    !!@_miau_authorization_performed
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
miau-0.1.0 lib/miau.rb