Sha256: 71f11a700c6f2c9f3d0cd8fb9aa7bcf91b057c7f8e8ff3c0b7f6810789b17db6

Contents?: true

Size: 916 Bytes

Versions: 4

Compression:

Stored size: 916 Bytes

Contents

module Auther
  class Keymaster
    attr_reader :account_name

    def self.namespace
      "auther"
    end

    def self.redirect_url_key delimiter: '_'
      [namespace, "redirect", "url"] * delimiter
    end

    def self.get_account_name session = {}
      matching_keys = session.keys.select { |key| key.to_s =~ /auther.+login/ }
      key = matching_keys.first || ''
      key.gsub("#{namespace}_", '').gsub "_login", ''
    end

    def self.get_account_login session = {}
      account_name = get_account_name session
      session[new(account_name).login_key]
    end

    def initialize account_name = nil
      @account_name = account_name
    end

    def login_key
      build_key "login"
    end

    def password_key
      build_key "password"
    end

    private

    def build_key key_name, delimiter: '_'
      [self.class.namespace, account_name, key_name].compact * delimiter
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
auther-1.0.0 lib/auther/keymaster.rb
auther-0.3.0 lib/auther/keymaster.rb
auther-0.2.0 lib/auther/keymaster.rb
auther-0.1.0 lib/auther/keymaster.rb