Class: Coercible::Coercer
- Inherits:
-
Object
- Object
- Coercible::Coercer
- Defined in:
- lib/project/coercer.rb,
lib/project/coercer/date.rb,
lib/project/coercer/hash.rb,
lib/project/coercer/time.rb,
lib/project/coercer/array.rb,
lib/project/coercer/float.rb,
lib/project/coercer/object.rb,
lib/project/coercer/string.rb,
lib/project/coercer/symbol.rb,
lib/project/coercer/decimal.rb,
lib/project/coercer/integer.rb,
lib/project/coercer/numeric.rb,
lib/project/coercer/date_time.rb,
lib/project/coercer/true_class.rb,
lib/project/coercer/false_class.rb,
lib/project/coercer/configurable.rb,
lib/project/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
86 87 88 89 |
# File 'lib/project/coercer.rb', line 86 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
23 24 25 |
# File 'lib/project/coercer.rb', line 23 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
30 31 32 |
# File 'lib/project/coercer.rb', line 30 def config @config end |
Class Method Details
.new {|| ... } ⇒ Coercer
Build a new coercer
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/project/coercer.rb', line 43 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
103 104 105 |
# File 'lib/project/coercer.rb', line 103 def [](klass) coercers[klass] || initialize_coercer(klass) end |