Module: Coercible::Coercer::Configurable

Included in:
Integer, String
Defined in:
lib/project/coercer/configurable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(coercer) ⇒ self

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.

Add configuration-specific option keys to the descendant

Returns:

  • (self)


11
12
13
14
# File 'lib/project/coercer/configurable.rb', line 11

def self.extended(coercer)
  coercer.accept_options :config_keys
  super
end

Instance Method Details

#config {|| ... } ⇒ Configuration

Build configuration object for the coercer class

Examples:


coercer_class = Class.new(Coercer::Object) do
  extend Configurable

  config_keys [ :foo, :bar ]
end

coercer_class.config do |config|
  config.foo = '1'
  config.bar = '2'
end

Yield Parameters:

Returns:



36
37
38
39
40
# File 'lib/project/coercer/configurable.rb', line 36

def config(&block)
  configuration = configuration_class.build(config_keys)
  yield configuration
  configuration
end

#config_nameSymbol

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.

Return configuration name in the global config

Returns:



47
48
49
# File 'lib/project/coercer/configurable.rb', line 47

def config_name
  name.downcase.split('::').last.to_sym
end

#configuration_classClass:Configuration

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.

Return configuration class

Returns:

  • (Class:Configuration)


56
57
58
# File 'lib/project/coercer/configurable.rb', line 56

def configuration_class
  Configuration
end