0.0
No release in over 3 years
Low commit activity in last 3 years
Configuration for Ruby objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.19.6

Runtime

~> 0.2.4
 Project Readme

MuchConfig

Configuration for Ruby objects.

Usage

Mixin MuchConfig in your e.g. MyClass Ruby object. Call the add_config DSL method and define MyClass::Config:

module MyClass
  include MuchConfig

  add_config

  def self.value1
    config.value1
  end

  class Config
    attr_accessor :value1

    def initialize
      @value1 = "default value for `value1`"
    end
  end
end

Configure MyClass using the MuchConfig API:

MyClass.config.value1 = "a custom value"

# OR

MyClass.configure do |config|
  config.value1 = "a custom value"
end

Define multiple named configs

You can define multiple named configs, e.g.:

module MyClass
  include MuchConfig

  add_config :values
  add_config :settings

  def self.value1
    values_config.value1
  end

  def self.setting1
    settings_config.setting1
  end

  class ValuesConfig
    attr_accessor :value1

    def initialize
      @value1 = "default value for `value1`"
    end
  end

  class SettingsConfig
    attr_accessor :setting1

    def initialize
      @setting1 = "default value for `setting1`"
    end
  end
end

Configure using the MuchConfig API:

MyClass.values_config.value1 = "a custom value"
MyClass.settings_config.setting1 = "a custom value"

# OR

MyClass.configure_values do |config|
  config.value1 = "a custom value"
end
MyClass.configure_settings do |config|
  config.setting1 = "a custom value"
end

Installation

Add this line to your application's Gemfile:

gem "much-config"

And then execute:

$ bundle

Or install it yourself as:

$ gem install much-config

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Added some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request