Sha256: 6f7ef7bda24ec28eefed12cad1c2666554f9c9d8beb50c7c0f6a579bcd67c73d

Contents?: true

Size: 910 Bytes

Versions: 2

Compression:

Stored size: 910 Bytes

Contents

# frozen_string_literal: true

class BCDD::Result
  class Config
    module ConstantAliases
      MAPPING = {
        'Result' => { target: ::Object, name: :Result, value: ::BCDD::Result }
      }.transform_values!(&:freeze).freeze

      OPTIONS = MAPPING.to_h do |option_name, mapping|
        affects = mapping.fetch(:target).name.freeze

        [option_name, { default: false, affects: [affects].freeze }]
      end.freeze

      Listener = ->(option_name, bool) do
        mapping = MAPPING.fetch(option_name)

        target, name, value = mapping.fetch_values(:target, :name, :value)

        defined = target.const_defined?(name, false)

        bool ? defined || target.const_set(name, value) : defined && target.send(:remove_const, name)
      end

      def self.switcher
        Switcher.new(options: OPTIONS, listener: Listener)
      end
    end

    private_constant :ConstantAliases
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bcdd-result-1.1.0 lib/bcdd/result/config/switchers/constant_aliases.rb
bcdd-result-1.0.0 lib/bcdd/result/config/switchers/constant_aliases.rb