Sha256: a0fc2303b58956599975c797ba40b716db6cd221b3fb830095685b5e4a1fb009

Contents?: true

Size: 890 Bytes

Versions: 4

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

require 'singleton'
require 'forwardable'

module ActiveShotgun
  class Config
    DEFAULT_CONFIG = {
      shotgun_site_name: 'pasind3-prod',
      shotgun_site_url: nil,
      shotgun_client_id: nil,
      shotgun_client_secret: nil,
    }.freeze

    include Singleton

    def initialize
      @config = Struct.new(*DEFAULT_CONFIG.keys).new(*DEFAULT_CONFIG.values)
    end
    attr_reader :config

    class << self
      extend Forwardable
      # Remove the need to call .instance everywhere
      def_delegators(
        :instance,
        :configure,
        *DEFAULT_CONFIG.keys.flat_map{ |key| [key, "#{key}="] }
      )
    end

    extend Forwardable
    def_delegators(
      :config,
      *DEFAULT_CONFIG.keys.flat_map{ |key| [key, "#{key}="] }
    )

    def configure(&block)
      return unless block

      yield(@config)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_shotgun-0.0.4 lib/active_shotgun/config.rb
active_shotgun-0.0.3 lib/active_shotgun/config.rb
active_shotgun-0.0.2.1 lib/active_shotgun/config.rb
active_shotgun-0.0.2 lib/active_shotgun/config.rb