Sha256: 93480a7b57fc3285ff8c688aa302550e880c0d19a1d09958d25a6a8918b079af

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Tokenable
  class Config
    # How long should the token last before it expires?
    # E.G: Tokenable::Config.lifespan = 7.days
    mattr_accessor :lifespan, default: nil

    # The secret used by JWT to encode the Token.
    # We default to Rails secret_key_base
    # This can be any 256 bit string.
    mattr_writer :secret, default: -> { Rails.application.secret_key_base }

    # The user model that we will perform actions on
    mattr_writer :user_class, default: -> { User }

    # We do this, as some of our defaults need to live in a Proc (as this library is loaded before Rails)
    # This means we can return the value when the method is called, instead of the Proc.
    def self.method_missing(method_name, *args, &block)
      class_variable_defined?("@@#{method_name}") ? proc_reader(method_name) : super
    end

    def self.respond_to_missing?(method_name, include_private = false)
      class_variable_defined?("@@#{method_name}") || super
    end

    def self.proc_reader(key)
      value = class_variable_get("@@#{key}")
      value.is_a?(Proc) ? value.call : value
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tokenable-ruby-0.1.0 lib/tokenable/config.rb