Module: ROM::Configurable::ClassMethods

Includes:
Methods
Defined in:
lib/rom/support/configurable/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#__config_dsl__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.



81
82
83
# File 'lib/rom/support/configurable/class_methods.rb', line 81

def __config_dsl__
  @__config_dsl__ ||= DSL.new
end

#__config_reader__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.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rom/support/configurable/class_methods.rb', line 86

def __config_reader__
  @__config_reader__ ||=
    begin
      reader = Module.new do
        def self.define(name)
          define_method(name) do
            config[name]
          end
        end
      end

      if included_modules.include?(InstanceMethods)
        include(reader)
      end

      extend(reader)

      reader
    end
end

#_settingsSettings

Return declared settings

Returns:



62
63
64
# File 'lib/rom/support/configurable/class_methods.rb', line 62

def _settings
  @_settings ||= Settings.new
end

#configConfig

Return configuration

Returns:



71
72
73
74
75
76
77
78
# File 'lib/rom/support/configurable/class_methods.rb', line 71

def config
  # The _settings provided to the Config remain shared between the class and the
  # Config. This allows settings defined _after_ accessing the config to become
  # available in subsequent accesses to the config. The config is duped when
  # subclassing to ensure it remains distinct between subclasses and parent classes
  # (see `.inherited` above).
  @config ||= Config.new(_settings)
end

#configure {|config| ... } ⇒ Object Originally defined in module Methods

Yields:

  • (config)

Raises:

#finalize!ROM::Configurable::Config Originally defined in module Methods

Finalize and freeze configuration

#inherited(subclass) ⇒ 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.



15
16
17
18
19
20
# File 'lib/rom/support/configurable/class_methods.rb', line 15

def inherited(subclass)
  super

  subclass.instance_variable_set("@_settings", _settings.dup)
  subclass.instance_variable_set("@_config", config.dup) if respond_to?(:config)
end

#setting(*args, **options) { ... } ⇒ ROM::Configurable::Config

Add a setting to the configuration

Parameters:

  • name (Mixed)

    The accessor key for the configuration value

  • default (Mixed)

    Default value for the setting

  • constructor (#call)

    Transformation given value will go through

  • reader (Boolean)

    Whether a reader accessor must be created

Yields:

  • A block can be given to add nested settings.

Returns:



38
39
40
41
42
43
44
45
46
# File 'lib/rom/support/configurable/class_methods.rb', line 38

def setting(*args, **options, &block)
  setting = __config_dsl__.setting(*args, **options, &block)

  _settings << setting

  __config_reader__.define(setting.name) if setting.reader?

  self
end

#settingsSet<Symbol>

Return declared settings

Returns:

  • (Set<Symbol>)


53
54
55
# File 'lib/rom/support/configurable/class_methods.rb', line 53

def settings
  @settings ||= Set[*_settings.map(&:name)]
end