Sha256: f266ab89ca055e46f02b702686b996e99489041ad6eb0622b4ec20d753d43c48

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

require "dry/core/class_attributes"

module ROM
  module SettingProxy
    extend Dry::Core::ClassAttributes

    private

    # @api private
    def respond_to_missing?(name, include_all = false)
      super || setting_mapping.key?(name)
    end

    # Delegate to config when accessing deprecated class attributes
    #
    # @api private
    def method_missing(name, *args, &block)
      return super unless setting_mapping.key?(name)

      mapping = setting_mapping[name]
      ns, key = mapping

      if args.empty?
        if mapping.empty?
          config[name]
        else
          config[ns][Array(key).first]
        end
      else
        value = args.first

        if mapping.empty?
          config[name] = value
        else
          Array(key).each { |k| config[ns][k] = value }
        end

        value
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-6.0.0.alpha1 lib/rom/compat/setting_proxy.rb