Sha256: dce68c135bd10cfdf3c06e0315add83e739aa2f491699f572cbfdc0c4ed90877

Contents?: true

Size: 1.94 KB

Versions: 9

Compression:

Stored size: 1.94 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( 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( 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( obj.value )
        return ln.resolve
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gloo-0.8.0 lib/gloo/objs/basic/alias.rb
gloo-0.7.7 lib/gloo/objs/basic/alias.rb
gloo-0.7.6 lib/gloo/objs/basic/alias.rb
gloo-0.7.5 lib/gloo/objs/basic/alias.rb
gloo-0.7.4 lib/gloo/objs/basic/alias.rb
gloo-0.7.3 lib/gloo/objs/basic/alias.rb
gloo-0.7.2 lib/gloo/objs/basic/alias.rb
gloo-0.7.1 lib/gloo/objs/basic/alias.rb
gloo-0.7.0 lib/gloo/objs/basic/alias.rb