Sha256: e84d9f2088c290b98b4332e10ef679ede42bc6070495d8b9112cca39d667b7cf

Contents?: true

Size: 743 Bytes

Versions: 3

Compression:

Stored size: 743 Bytes

Contents

module Nyauth
  module ClientConcern
    extend ActiveSupport::Concern
    included do |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.6.2 app/controllers/concerns/nyauth/client_concern.rb
nyauth-0.6.1 app/controllers/concerns/nyauth/client_concern.rb
nyauth-0.6.0 app/controllers/concerns/nyauth/client_concern.rb