Sha256: 951ce4a2b0fbe97f41a9e4c2a074ce681d84c49297dc94a113eeb09839afc897

Contents?: true

Size: 834 Bytes

Versions: 11

Compression:

Stored size: 834 Bytes

Contents

module Adhoq
  module AuthorizationMethods
    extend ActiveSupport::Concern

    included do |controller|
      controller.before_action Authorizer.new

      helper_method :adhoq_current_user
    end

    class Authorizer
      def before(controller)
        return true if authorization.call(controller)

        if failure = Adhoq.config.authorization_failure_action
          failure.call(controller)
        else
          controller.send(:render, text: 'No such file or directory', status: :not_found)
        end
      end

      private

      def authorization
        @authorization ||= Adhoq.config.callablize(:authorization)
      end
    end

    private

    def adhoq_current_user
      @_adhoq_current_user_proc ||= Adhoq.config.callablize(:current_user)

      @_adhoq_current_user_proc.call(self)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
adhoq-1.0.2 app/controllers/adhoq/authorization_methods.rb
adhoq-1.0.1 app/controllers/adhoq/authorization_methods.rb
adhoq-1.0.0 app/controllers/adhoq/authorization_methods.rb
adhoq-0.5.0 app/controllers/adhoq/authorization_methods.rb
adhoq-0.5.0.beta1 app/controllers/adhoq/authorization_methods.rb
adhoq-0.4.0 app/controllers/adhoq/authorization_methods.rb
adhoq-0.3.0 app/controllers/adhoq/authorization_methods.rb
adhoq-0.2.0 app/controllers/adhoq/authorization_methods.rb
adhoq-0.1.2 app/controllers/adhoq/authorization_methods.rb
adhoq-0.1.1 app/controllers/adhoq/authorization_methods.rb
adhoq-0.1.0 app/controllers/adhoq/authorization_methods.rb