Sha256: dda7c673b143bdf26ce76dbcd1e5f6510c014e5868fffb8c14ae9de604b02fe6

Contents?: true

Size: 1.97 KB

Versions: 20

Compression:

Stored size: 1.97 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# A String.
#

module Gloo
  module Objs
    class Alias < Gloo::Core::Obj

      KEYWORD = 'alias'.freeze
      KEYWORD_SHORT = 'ln'.freeze
      ALIAS_REFERENCE = '*'.freeze

      #
      # The name of the object type.
      #
      def self.typename
        return KEYWORD
      end

      #
      # The short name of the object type.
      #
      def self.short_typename
        return KEYWORD_SHORT
      end

      #
      # Set the value with any necessary type conversions.
      #
      def set_value( new_value )
        self.value = new_value.to_s
      end

      # ---------------------------------------------------------------------
      #    Messages
      # ---------------------------------------------------------------------

      #
      # Get a list of message names that this object receives.
      #
      def self.messages
        return super + %w[resolve]
      end

      #
      # Check to see if the referenced object exists.
      #
      def msg_resolve
        pn = Gloo::Core::Pn.new( @engine, self.value )
        s = pn.exists?
        @engine.heap.it.set_to s
        return s
      end

      # ---------------------------------------------------------------------
      #    Resolve
      # ---------------------------------------------------------------------

      #
      # Is the object an alias  If so, then resolve it.
      # The ref_name is the name used to refer to the object.
      # If it ends with the * then we won't resolve the alias since
      # we are trying to refer to the alias itself.
      #
      def self.resolve_alias( engine, obj, ref_name = nil )
        return nil unless obj
        return obj unless obj.type_display == Gloo::Objs::Alias.typename
        return obj if ref_name&.end_with?( ALIAS_REFERENCE )

        ln = Gloo::Core::Pn.new( engine, obj.value )
        return ln.resolve
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
gloo-3.5.0 lib/gloo/objs/basic/alias.rb
gloo-3.4.1 lib/gloo/objs/basic/alias.rb
gloo-3.4.0 lib/gloo/objs/basic/alias.rb
gloo-3.3.0 lib/gloo/objs/basic/alias.rb
gloo-3.2.0 lib/gloo/objs/basic/alias.rb
gloo-3.1.1 lib/gloo/objs/basic/alias.rb
gloo-3.1.0 lib/gloo/objs/basic/alias.rb
gloo-3.0.1 lib/gloo/objs/basic/alias.rb
gloo-3.0.0 lib/gloo/objs/basic/alias.rb
gloo-2.5.0 lib/gloo/objs/basic/alias.rb
gloo-2.4.3 lib/gloo/objs/basic/alias.rb
gloo-2.4.2 lib/gloo/objs/basic/alias.rb
gloo-2.4.1 lib/gloo/objs/basic/alias.rb
gloo-2.4.0 lib/gloo/objs/basic/alias.rb
gloo-2.3.1 lib/gloo/objs/basic/alias.rb
gloo-2.2.0 lib/gloo/objs/basic/alias.rb
gloo-2.1.0 lib/gloo/objs/basic/alias.rb
gloo-2.0.2 lib/gloo/objs/basic/alias.rb
gloo-2.0.1 lib/gloo/objs/basic/alias.rb
gloo-2.0.0 lib/gloo/objs/basic/alias.rb