module Pakyow::Support::Configurable

Makes an object configurable.

class ConfigurableObject
  include Configurable

  setting :foo, "default"
  setting :bar

  defaults :development do
    setting :bar, "bar"
  end
end

class ConfigurableSubclass < ConfigurableObject
  configure :development do
    config.foo = "development"
  end

  configure :production do
    config.foo = "production"
  end
end

instance = ConfigurableSubclass.new
instance.configure! :development

instance.config.foo
# => "development"
instance.config.bar
# => "bar"

Public Class Methods

included(base) click to toggle source

@api private

# File lib/pakyow/support/configurable.rb, line 46
def self.included(base)
  base.extend ClassState
  base.class_state :__config, default: Config.new(base), inheritable: true
  base.class_state :__config_environments, default: Concurrent::Hash.new, inheritable: true

  unless base.instance_of?(Module)
    base.prepend Initializer
  end

  base.include CommonMethods
  base.extend  ClassMethods, CommonMethods
end

Private Instance Methods

__config_environments() click to toggle source
# File lib/pakyow/support/configurable.rb, line 59
        def __config_environments
  self.class.__config_environments
end