Sha256: 4e2e97f9d9a6467aada158b5171d7851c21d23609eefa19054a484bb8249779b

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# Show a system notification.
#

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

      KEYWORD = 'alert'.freeze
      KEYWORD_SHORT = '!'.freeze

      MISSING_EXPR_ERR = 'Missing Expression!'.freeze
      NO_RESULT_ERR = 'Expression evaluated with no result!'.freeze

      #
      # Run the verb.
      #
      def run
        unless @tokens.token_count > 1
          $engine.err MISSING_EXPR_ERR
          return
        end

        expr = Gloo::Expr::Expression.new( @tokens.params )
        result = expr.evaluate

        if result
          $engine.heap.it.set_to result
          post_alert result
        else
          $engine.err NO_RESULT_ERR
        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

      #
      # Post the alert for the specific platform.
      # Notice is not posted if we're in quiet mode.
      #
      def post_alert( msg )
        $log.info msg
        return if $engine.args.quiet?

        post_osx msg
      end

      #
      # Post the alert on the Mac OSX.
      #
      def post_osx( msg )
        cmd1 = '/usr/bin/osascript -e "display notification \"'
        cmd2 = '\" with title \"Gloo\" "'
        system( cmd1 + msg.to_s + cmd2 )
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gloo-0.8.0 lib/gloo/verbs/alert.rb
gloo-0.7.7 lib/gloo/verbs/alert.rb
gloo-0.7.6 lib/gloo/verbs/alert.rb
gloo-0.7.5 lib/gloo/verbs/alert.rb
gloo-0.7.4 lib/gloo/verbs/alert.rb
gloo-0.7.3 lib/gloo/verbs/alert.rb
gloo-0.7.2 lib/gloo/verbs/alert.rb
gloo-0.7.1 lib/gloo/verbs/alert.rb
gloo-0.7.0 lib/gloo/verbs/alert.rb