Sha256: ef86a87bb82789f0cfba43c8f29aa70e6997dd36eafa516a87b5d277e66c0956

Contents?: true

Size: 943 Bytes

Versions: 4

Compression:

Stored size: 943 Bytes

Contents

# frozen_string_literal: true

require "memery"

module UmbrellioUtils
  GLOBAL_MUTEX = Mutex.new

  Dir["#{__dir__}/*/*.rb"].each { |file_path| require_relative(file_path) }

  extend self

  def included(othermod)
    super
    othermod.extend(self)
  end

  # rubocop:disable Style/ClassVars
  def config
    synchronize do
      @@config ||= Struct
        .new(:store_table_name, :http_client_name, keyword_init: true)
        .new(**default_settings)
    end
  end

  # rubocop:enable Style/ClassVars

  def configure
    synchronize { yield config }
  end

  def extend_util!(module_name, &block)
    const = UmbrellioUtils.const_get(module_name)
    synchronize { const.class_eval(&block) }
  end

  private

  def default_settings
    {
      store_table_name: :store,
      http_client_name: :application_httpclient,
    }
  end

  def synchronize(&block)
    GLOBAL_MUTEX.owned? ? yield : GLOBAL_MUTEX.synchronize(&block)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
umbrellio-utils-0.3.2 lib/umbrellio_utils.rb
umbrellio-utils-0.3.1 lib/umbrellio_utils.rb
umbrellio-utils-0.3.0 lib/umbrellio_utils.rb
umbrellio-utils-0.2.0 lib/umbrellio_utils.rb