Sha256: 6794cb261ea88d6bd2719ee42fdb122ea7c1f74013d2cab43027eaf1d0394eef

Contents?: true

Size: 1.56 KB

Versions: 20

Compression:

Stored size: 1.56 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# Run a script.
# Shortcut for telling a script to run.
#

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

      KEYWORD = 'run'.freeze
      KEYWORD_SHORT = 'r'.freeze
      EVALUATE_RUN = '~>'.freeze
      MISSING_EXPR_ERR = 'Missing Expression!'.freeze

      #
      # Run the verb.
      #
      def run
        if @tokens.token_count < 2
          @engine.err MISSING_EXPR_ERR
          return
        end

        if @tokens.second == EVALUATE_RUN
          run_expression
        else
          run_script
        end
      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

      #
      # Run a script specified by pathname
      #
      def run_script
        Gloo::Exec::Runner.run( @engine, @tokens.second )
      end

      #
      # Evaluate an expression and run that.
      #
      def run_expression
        unless @tokens.token_count > 2
          @engine.err MISSING_EXPR_ERR
          return
        end

        expr = Gloo::Expr::Expression.new( @engine, @tokens.params[ 1..-1 ] )
        @engine.parser.run expr.evaluate
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

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