Class: Coercible::Coercer
- Inherits:
-
Object
- Object
- Coercible::Coercer
- Defined in:
- lib/coercible/coercer.rb,
lib/coercible/coercer/date.rb,
lib/coercible/coercer/hash.rb,
lib/coercible/coercer/time.rb,
lib/coercible/coercer/array.rb,
lib/coercible/coercer/float.rb,
lib/coercible/coercer/object.rb,
lib/coercible/coercer/string.rb,
lib/coercible/coercer/symbol.rb,
lib/coercible/coercer/decimal.rb,
lib/coercible/coercer/integer.rb,
lib/coercible/coercer/numeric.rb,
lib/coercible/coercer/date_time.rb,
lib/coercible/coercer/true_class.rb,
lib/coercible/coercer/false_class.rb,
lib/coercible/coercer/configurable.rb,
lib/coercible/coercer/time_coercions.rb
Overview
Coercer object
Defined Under Namespace
Modules: Configurable, TimeCoercions Classes: Array, Date, DateTime, Decimal, FalseClass, Float, Hash, Integer, Numeric, Object, String, Symbol, Time, TrueClass
Instance Attribute Summary collapse
-
#coercers ⇒ Array<Coercer::Object>
readonly
private
Return coercer instances.
-
#config ⇒ Configuration
readonly
private
Returns global configuration for coercers.
Class Method Summary collapse
-
.new {|| ... } ⇒ Coercer
Build a new coercer.
Instance Method Summary collapse
-
#[](klass) ⇒ Coercer::Object
Access a specific coercer object for the given type.
-
#initialize(config, coercers = {}) ⇒ undefined
constructor
private
Initialize a new coercer instance.
Constructor Details
#initialize(config, coercers = {}) ⇒ undefined
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.
Initialize a new coercer instance
84 85 86 87 |
# File 'lib/coercible/coercer.rb', line 84 def initialize(config, coercers = {}) @coercers = coercers @config = config end |
Instance Attribute Details
#coercers ⇒ Array<Coercer::Object> (readonly)
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 coercer instances
21 22 23 |
# File 'lib/coercible/coercer.rb', line 21 def coercers @coercers end |
#config ⇒ Configuration (readonly)
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.
Returns global configuration for coercers
28 29 30 |
# File 'lib/coercible/coercer.rb', line 28 def config @config end |
Class Method Details
.new {|| ... } ⇒ Coercer
Build a new coercer
41 42 43 44 45 46 47 48 49 50 51 |
# 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 |
Instance Method Details
#[](klass) ⇒ Coercer::Object
Access a specific coercer object for the given type
101 102 103 |
# File 'lib/coercible/coercer.rb', line 101 def [](klass) coercers[klass] || initialize_coercer(klass) end |