Sha256: 5d6311417b449ecb248fb3fcc888c92dc5320318447281576f76a691225424c2

Contents?: true

Size: 641 Bytes

Versions: 7

Compression:

Stored size: 641 Bytes

Contents

# frozen_string_literal: true

module Stairwell
  class TypeObjectAssigner
    attr_reader :name, :value, :all_validations

    def self.run(...)
      new(...).run
    end

    def initialize(name:, value:, all_validations:)
      @name = name
      @value = value
      @all_validations = all_validations
    end

    def run
      type_object
    end

    private

    def proposed_type
      all_validations[name]
    end

    def type_object
      if proposed_type.is_a?(Array)
        Types::InType.new(value, proposed_type.first)
      else
        Object.const_get(TYPE_CLASSES[proposed_type]).new(value)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
stairwell-0.6.5 lib/stairwell/type_object_assigner.rb
stairwell-0.6.4 lib/stairwell/type_object_assigner.rb
stairwell-0.6.3 lib/stairwell/type_object_assigner.rb
stairwell-0.6.2 lib/stairwell/type_object_assigner.rb
stairwell-0.6.1 lib/stairwell/type_object_assigner.rb
stairwell-0.6.0 lib/stairwell/type_object_assigner.rb
stairwell-0.5.0 lib/stairwell/type_object_assigner.rb