Sha256: 2bd5f64507acc446b99cdbb69ee8988c040efde1e67fc4650df253c84a4f12f6

Contents?: true

Size: 809 Bytes

Versions: 3

Compression:

Stored size: 809 Bytes

Contents

module Nyauth
  module ClientConcern
    extend ActiveSupport::Concern
    included do |base|
      next unless base.ancestors.include?(ActionController::Base)
      helper_method :nyauth_client_class
      helper_method :nyauth_client_name
    end

    def initialize
      @nyauth_client_classes = {}

      super
    end

    private

    def nyauth_mounted_path
      request.script_name.presence || "/#{request.path.split('/').try(:second)}"
    end

    # specify client class from nyauth_mounted_path
    def nyauth_client_class
      @nyauth_client_classes[nyauth_mounted_path] ||= nyauth_mounted_path[1..-1].classify.constantize
    rescue
      @nyauth_client_classes[nyauth_mounted_path] = User
    end

    def nyauth_client_name
      nyauth_client_class.name.underscore.to_sym
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nyauth-0.7.2 app/controllers/concerns/nyauth/client_concern.rb
nyauth-0.7.1 app/controllers/concerns/nyauth/client_concern.rb
nyauth-0.7.0 app/controllers/concerns/nyauth/client_concern.rb