Sha256: 90b64cce399f63bd7b9c7e4915c8efe65599b69f8b903efa9ac85fc7d7fd3562

Contents?: true

Size: 679 Bytes

Versions: 10

Compression:

Stored size: 679 Bytes

Contents

 module Compel
  module Coercion

    class Result

      attr_reader :coerced,
                  :value,
                  :klass,
                  :error

      def initialize(coerced, value, klass, coercion_error = nil)
        @coerced = coerced
        @value = value
        @klass = klass
        @error = coercion_error.nil? ? standard_error : coercion_error
      end

      def valid?
        @error.nil?
      end

      private

      def standard_error
        if !klass.nil? && coerced.nil?
          "'#{value}' is not a valid #{klass_final_type}"
        end
      end

      def klass_final_type
        "#{klass}".split('::')[-1]
      end

    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
compel-0.5.1 lib/compel/coercion/result.rb
compel-0.5.0 lib/compel/coercion/result.rb
compel-0.4.3 lib/compel/coercion/result.rb
compel-0.4.2 lib/compel/coercion/result.rb
compel-0.4.0 lib/compel/coercion/result.rb
compel-0.3.7 lib/compel/coercion/result.rb
compel-0.3.6 lib/compel/coercion/result.rb
compel-0.3.4 lib/compel/coercion/result.rb
compel-0.3.2 lib/compel/coercion/result.rb
compel-0.3.1 lib/compel/coercion/result.rb