Sha256: 735f57fb1b9ace2e4adc77cf3ce9522c5199f394682eb0ccb13ace144877b301
Contents?: true
Size: 1.36 KB
Versions: 7
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true require_relative 'configuration' module Necromancer # Abstract converter used internally as a base for other converters # # @api private class Converter # Create an abstract converter # # @param [Object] source # the source object type # # @param [Object] target # the target object type # # @api public def initialize(source = nil, target = nil) @source = source if source @target = target if target @config ||= Configuration.new end # Run converter # # @api private def call(*) raise NotImplementedError end # Creates anonymous converter # # @api private def self.create(&block) Class.new(self) do define_method(:initialize) { |*a| block.call(self, *a) } define_method(:call) { |value| convert.call(value) } end.new end # Fail with conversion type error # # @param [Object] value # the value that cannot be converted # # @api private def raise_conversion_type(value) raise ConversionTypeError, "'#{value}' could not be converted " \ "from `#{source}` into `#{target}` " end attr_accessor :source attr_accessor :target attr_accessor :convert protected attr_reader :config end # Converter end # Necromancer
Version data entries
7 entries across 7 versions & 2 rubygems