Parent

Methods

Coercible::Coercer

Coercer object

@example

coercer = Coercible::Coercer.new

coercer[String].to_boolean('yes') # => true
coercer[Integer].to_string(1)     # => '1'

@api public

Attributes

coercers[R]

Return coercer instances

@return [Array<Coercer::Object>]

@api private

config[R]

Returns global configuration for coercers

@return [Configuration]

@api private

Public Class Methods

new(&block) click to toggle source

Build a new coercer

@example

Coercible::Coercer.new { |config| # set configuration }

@yieldparam [Configuration]

@return [Coercer]

@api public

# File lib/coercible/coercer.rb, line 41
def self.new(&block)
  configuration = Configuration.build(config_keys)

  configurable_coercers.each do |coercer|
    configuration.send("#{coercer.config_name}=", coercer.config)
  end

  yield(configuration) if block_given?

  super(configuration)
end
new(config, coercers = {}) click to toggle source

Initialize a new coercer instance

@param [Hash] coercers

@param [Configuration] config

@return [undefined]

@api private

# File lib/coercible/coercer.rb, line 84
def initialize(config, coercers = {})
  @coercers = coercers
  @config   = config
end

Public Instance Methods

[](klass) click to toggle source

Access a specific coercer object for the given type

@example

coercer[String] # => string coercer
coercer[Integer] # => integer coercer

@param [Class] type

@return [Coercer::Object]

@api public

# File lib/coercible/coercer.rb, line 101
def [](klass)
  coercers[klass] || initialize_coercer(klass)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.