Sha256: e69ea36ca6456ec2cacee9b137033456ceb5e91d6c7a0cc7d5173b02772cd393

Contents?: true

Size: 910 Bytes

Versions: 9

Compression:

Stored size: 910 Bytes

Contents

module Finitio
  class AliasType < Type

    def initialize(target, name, metadata = nil)
      unless target.is_a?(Type)
        raise ArgumentError, "Type expected for target type, got `#{target}`"
      end
      if name.nil?
        raise ArgumentError, "Alias name cannot be nil"
      end

      super(name, metadata)
      @target = target
    end
    attr_reader :target

    def default_name
      @name
    end

    [
      :representator,
      :dress,
      :undress,
      :include?,
      :==,
      :eql?,
      :hash,
      :to_s
    ].each do |meth|
      define_method(meth) do |*args, &bl|
        @target.send(meth, *args, &bl)
      end
    end

    def resolve_proxies(system)
      AliasType.new(target.resolve_proxies(system), name, metadata)
    end

    def unconstrained
      AliasType.new(target.unconstrained, name, metadata)
    end

  end # class AliasType
end # module Finitio

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
finitio-0.12.0 lib/finitio/type/alias_type.rb
finitio-0.11.4 lib/finitio/type/alias_type.rb
finitio-0.11.3 lib/finitio/type/alias_type.rb
finitio-0.11.2 lib/finitio/type/alias_type.rb
finitio-0.11.1 lib/finitio/type/alias_type.rb
finitio-0.10.0 lib/finitio/type/alias_type.rb
finitio-0.9.1 lib/finitio/type/alias_type.rb
finitio-0.9.0 lib/finitio/type/alias_type.rb
finitio-0.8.0 lib/finitio/type/alias_type.rb