Sha256: e77e598c4eb09b83249ffe2c5e411ecb53211cce0a5ac6fe62691331a7cc4cf6

Contents?: true

Size: 1.68 KB

Versions: 19

Compression:

Stored size: 1.68 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# Create an object, optionally of a type.
#

module Gloo
  module Verbs
    class Tell < Gloo::Core::Verb

      KEYWORD = 'tell'.freeze
      KEYWORD_SHORT = '->'.freeze
      TO = 'to'.freeze
      OBJ_NOT_FOUND_ERR = 'Object was not found: '.freeze
      UNKNOWN_MSG_ERR = 'Missing message!'.freeze

      #
      # Run the verb.
      #
      def run
        setup_msg
        return unless @msg

        setup_target
        dispatch_msg
      end

      #
      # Get the Verb's keyword.
      #
      def self.keyword
        return KEYWORD
      end

      #
      # Get the Verb's keyword shortcut.
      #
      def self.keyword_shortcut
        return KEYWORD_SHORT
      end

      # ---------------------------------------------------------------------
      #    Private functions
      # ---------------------------------------------------------------------

      private

      #
      # Lookup the message to send.
      #
      def setup_msg
        @msg = @tokens.after_token( TO )

        @engine.err( UNKNOWN_MSG_ERR ) unless @msg
      end

      #
      # Setup the target of the message.
      #
      def setup_target
        @obj_name = @tokens.second
        pn = Gloo::Core::Pn.new( @engine, @obj_name )
        @target_obj = pn.resolve
      end

      #
      # Dispatch the message to the target object.
      #
      def dispatch_msg
        if @target_obj
          Gloo::Exec::Dispatch.message(
            @engine, @msg, @target_obj, @params )
        else
          @engine.err "#{OBJ_NOT_FOUND_ERR} #{@obj_name}"
        end
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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