Module: Pakyow::Support::Configurable

Defined in:
lib/pakyow/support/configurable.rb,
lib/pakyow/support/configurable/config.rb,
lib/pakyow/support/configurable/setting.rb

Overview

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"

Defined Under Namespace

Modules: ClassMethods, CommonMethods, Initializer Classes: Config, Setting

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
49
50
51
52
53
54
55
56
57
# 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