Sha256: 3dba1c537f518c68863e14cd7974be079ecfa6fa5c91513ab534f7bb3fd6e616

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'singleton'
module Fernet
  # Public - singleton class used to globally set various
  #          configuration defaults
  class Configuration
    include Singleton

    # Public: Returns whether to enforce a message TTL (true or false)
    attr_accessor :enforce_ttl

    # Public: Returns how many seconds messages are considered valid for
    attr_accessor :ttl

    # Public: used to configure fernet, typically invoked in an initialization
    #   routine
    #
    # Sets the following values:
    #
    # * enforce_ttl: true
    # * ttl: 60
    #
    # Yields the singleton configuration object, where above defaults can be
    #   overridden
    #
    # Examples
    #
    # Fernet::Configuration.run do |config|
    #   config.enforce_ttl = false
    # end
    def self.run
      self.instance.enforce_ttl = true
      self.instance.ttl         = 60
      yield self.instance if block_given?
    end

    class << self
      def method_missing(method)
        if self.instance.respond_to?(method)
          self.instance.send(method)
        else
          super
        end
      end

      def respond_to?(method)
        self.instance.respond_to?(method) || super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fernet-2.0.rc2 lib/fernet/configuration.rb