class AMA::Entity::Mapper::Type::BuiltIn::RationalType
Rational type description
Constants
- INSTANCE
Public Class Methods
new()
click to toggle source
Calls superclass method
AMA::Entity::Mapper::Type::new
# File lib/ama-entity-mapper/type/builtin/rational_type.rb, line 13 def initialize super(Rational) normalizer_block do |entity, *| entity.to_s end define_denormalizer define_factory enumerator_block do |*| ::Enumerator.new { |*| } end injector_block { |*| } end
Private Instance Methods
define_denormalizer()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/rational_type.rb, line 32 def define_denormalizer denormalizer_block do |input, _, ctx| break input if input.is_a?(Rational) input = input.to_s if input.is_a?(Symbol) break Rational(input) if input.is_a?(String) singleton_class.send(:include, Mixin::Errors) message = "String input expected (like '2.3'), " \ "#{input.class} received: #{input}" mapping_error(message, context: ctx) end end
define_factory()
click to toggle source
# File lib/ama-entity-mapper/type/builtin/rational_type.rb, line 44 def define_factory factory_block do |_, _, ctx| singleton_class.send(:include, Mixin::Errors) message = 'Rational type could not be instantiated directly, ' \ 'it only supports normalization and denormalization' compliance_error(message, context: ctx) end end