Module: ContainerConfig::Coercer

Defined in:
lib/container_config/coercer.rb,
lib/container_config/coercer/base.rb,
lib/container_config/coercer/float.rb,
lib/container_config/coercer/string.rb,
lib/container_config/coercer/symbol.rb,
lib/container_config/coercer/boolean.rb,
lib/container_config/coercer/integer.rb,
lib/container_config/coercer/ssl_key.rb,
lib/container_config/coercer/ssl_certificate.rb,
lib/container_config/coercer/ssl_verify_mode.rb

Overview

Contains classes and methods for type coercion

Defined Under Namespace

Classes: Base, Boolean, Float, Integer, SslCertificate, SslKey, SslVerifyMode, String, Symbol

Class Method Summary collapse

Class Method Details

.coerce_value(value, value_type = nil, options = {}) ⇒ Object

Coerces a given value into a requested type

Parameters:

  • value (Object)

    value to coerce

  • value_type (Symbol) (defaults to: nil)

    requested type such as :boolean, :integer, :string, :symbol, :ssl_verify_mode, :ssl_certificate, or :ssl_key

  • options (Hash) (defaults to: {})

    Options Hash

Options Hash (options):

  • :coerce_nil (Boolean)

    where to coerce nil values (defaults to true)

Returns:

  • (Object)

    coerced value



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/container_config/coercer.rb', line 28

def self.coerce_value(value, value_type = nil, options = {})
  return value unless value_type

  return value if options[:coerce_nil] == false && value.nil?

  value_type = value_type.to_sym

  ContainerConfig.coercers.each do |coercer|
    return coercer.coerce(value) if coercer.type == value_type
  end

  ContainerConfig.logger.warn { "Could not find valid coercion type for #{value_type}" }
  value
end

.default_coercersArray<ContainerConfig::Coercer::Base>

Array of default coercers

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/container_config/coercer.rb', line 48

def self.default_coercers
  [
    ContainerConfig::Coercer::Boolean.new,
    ContainerConfig::Coercer::Float.new,
    ContainerConfig::Coercer::Integer.new,
    ContainerConfig::Coercer::SslCertificate.new,
    ContainerConfig::Coercer::SslKey.new,
    ContainerConfig::Coercer::SslVerifyMode.new,
    ContainerConfig::Coercer::String.new,
    ContainerConfig::Coercer::Symbol.new
  ]
end