Sha256: d824fdd3971fc254772b51fd6efd5443f11361d651503f2de13022f3c729d649

Contents?: true

Size: 697 Bytes

Versions: 6

Compression:

Stored size: 697 Bytes

Contents

module Compel
  module Coercion

    class Type

      attr_accessor :value,
                    :options

      def self.coerce(value, options = {})
        new(value, options).coerce
      end

      def initialize(value, options = {})
        @value = value
        @options = options
      end

      def coerce
        result = coerce_value

        # There are some special cases that
        # we need to build a custom error
        if result.is_a?(Result)
          return result
        end

        Coercion::Result.new(result, value, self.class)
      end

      class << self

        def human_name
          "#{self.name.split('::')[-1]}"
        end

      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
compel-0.5.1 lib/compel/coercion/types/type.rb
compel-0.5.0 lib/compel/coercion/types/type.rb
compel-0.4.3 lib/compel/coercion/types/type.rb
compel-0.4.2 lib/compel/coercion/types/type.rb
compel-0.4.0 lib/compel/coercion/types/type.rb
compel-0.3.7 lib/compel/coercion/types/type.rb