Sha256: 91887390017d4613b6f137afa94f118a5134438b8ccfb5aa147b4f6788390d00

Contents?: true

Size: 516 Bytes

Versions: 3

Compression:

Stored size: 516 Bytes

Contents

module Rasti
  module Types
    class Model

      include Castable

      attr_reader :model

      def self.[](model)
        new(model)
      end

      def to_s
        "#{self.class}[#{model}]"
      end
      alias_method :inspect, :to_s

      private

      def initialize(model)
        @model = model
      end

      def valid?(value)
        value.is_a?(::Hash) || value.is_a?(model)
      end

      def transform(value)
        value.is_a?(model) ? value : model.new(value)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rasti-types-2.0.1 lib/rasti/types/model.rb
rasti-types-2.0.0 lib/rasti/types/model.rb
rasti-types-1.1.2 lib/rasti/types/model.rb