Sha256: d42c8c324e810acc2cd10e15b5d3b071e64f1a9e747cb08498d7a0ebe935627c

Contents?: true

Size: 827 Bytes

Versions: 18

Compression:

Stored size: 827 Bytes

Contents

module Config
  # The main configuration backbone
  class Configuration < Module
    # Accepts configuration options,
    # initializing a module that can be used to extend
    # the necessary class with the provided config methods
    def initialize(**attributes)
      attributes.each do |name, default|
        define_reader(name, default)
        define_writer(name)
      end
    end

    private

    def define_reader(name, default)
      variable = :"@#{name}"

      define_method(name) do
        if instance_variable_defined?(variable)
          instance_variable_get(variable)
        else
          default
        end
      end
    end

    def define_writer(name)
      variable = :"@#{name}"

      define_method("#{name}=") do |value|
        instance_variable_set(variable, value)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
config-5.5.2 lib/config/configuration.rb
config-5.5.1 lib/config/configuration.rb
config-5.4.0 lib/config/configuration.rb
config-5.3.0 lib/config/configuration.rb
config-5.2.0 lib/config/configuration.rb
config-5.1.0 lib/config/configuration.rb
config-5.0.0 lib/config/configuration.rb
config-4.2.1 lib/config/configuration.rb
config-4.2.0 lib/config/configuration.rb
config-4.1.0 lib/config/configuration.rb
config-4.0.0 lib/config/configuration.rb
config-3.1.1 lib/config/configuration.rb
config-3.1.0 lib/config/configuration.rb
config-3.0.0 lib/config/configuration.rb
config-2.2.3 lib/config/configuration.rb
config-2.2.2 lib/config/configuration.rb
config-2.2.1 lib/config/configuration.rb
config-2.1.0 lib/config/configuration.rb