Module: Chronicle::ETL::Configurable::ClassMethods

Defined in:
lib/chronicle/etl/configurable.rb

Overview

Class methods for classes that have Configurable mixed in

Instance Method Summary collapse

Instance Method Details

#all_required_settingsObject

Filters settings to those that are required.



168
169
170
# File 'lib/chronicle/etl/configurable.rb', line 168

def all_required_settings
  all_settings.select { |_name, setting| setting.required } || {}
end

#all_settingsObject

Collect all settings defined on this class and its ancestors (that have Configurable mixin included)



159
160
161
162
163
164
165
# File 'lib/chronicle/etl/configurable.rb', line 159

def all_settings
  if superclass.include?(Chronicle::ETL::Configurable)
    superclass.all_settings.merge(settings)
  else
    settings
  end
end

#config_with_defaultsObject



180
181
182
183
# File 'lib/chronicle/etl/configurable.rb', line 180

def config_with_defaults
  s = all_settings.transform_values(&:default)
  Config.new(s)
end

#setting(name, default: nil, required: false, type: nil, description: nil) ⇒ Object

Macro for creating a setting on a class Chronicle::ETL::Configurable

Examples:

Basic usage

setting :when, type: :date, required: true

Parameters:

  • name (String)

    Name of the setting

  • required (Boolean) (defaults to: false)

    whether setting is required

  • default (Object) (defaults to: nil)

    Default value

  • type (Symbol) (defaults to: nil)

    Type

See Also:



152
153
154
155
# File 'lib/chronicle/etl/configurable.rb', line 152

def setting(name, default: nil, required: false, type: nil, description: nil)
  s = Setting.new(default, required, type, description)
  settings[name] = s
end

#setting_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/chronicle/etl/configurable.rb', line 176

def setting_exists?(name)
  all_settings.keys.include? name
end

#settingsObject



172
173
174
# File 'lib/chronicle/etl/configurable.rb', line 172

def settings
  @settings ||= {}
end