gloo 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +3 -3
  5. data/Rakefile +6 -6
  6. data/bin/console +4 -4
  7. data/gloo.gemspec +19 -18
  8. data/lib/gloo.rb +6 -6
  9. data/lib/gloo/app/args.rb +30 -31
  10. data/lib/gloo/app/engine.rb +33 -28
  11. data/lib/gloo/app/help.rb +17 -11
  12. data/lib/gloo/app/info.rb +3 -3
  13. data/lib/gloo/app/log.rb +17 -17
  14. data/lib/gloo/app/mode.rb +4 -4
  15. data/lib/gloo/app/settings.rb +43 -40
  16. data/lib/gloo/core/baseo.rb +7 -7
  17. data/lib/gloo/core/dictionary.rb +30 -27
  18. data/lib/gloo/core/error.rb +50 -0
  19. data/lib/gloo/core/event_manager.rb +17 -19
  20. data/lib/gloo/core/factory.rb +92 -39
  21. data/lib/gloo/core/gloo_system.rb +49 -54
  22. data/lib/gloo/core/heap.rb +15 -13
  23. data/lib/gloo/core/it.rb +5 -5
  24. data/lib/gloo/core/literal.rb +7 -7
  25. data/lib/gloo/core/obj.rb +89 -79
  26. data/lib/gloo/core/obj_finder.rb +9 -14
  27. data/lib/gloo/core/op.rb +8 -8
  28. data/lib/gloo/core/parser.rb +25 -26
  29. data/lib/gloo/core/pn.rb +65 -50
  30. data/lib/gloo/core/runner.rb +26 -0
  31. data/lib/gloo/core/script.rb +7 -7
  32. data/lib/gloo/core/tokens.rb +39 -41
  33. data/lib/gloo/core/verb.rb +30 -19
  34. data/lib/gloo/expr/expression.rb +35 -43
  35. data/lib/gloo/expr/l_boolean.rb +7 -6
  36. data/lib/gloo/expr/l_integer.rb +5 -4
  37. data/lib/gloo/expr/l_string.rb +13 -15
  38. data/lib/gloo/expr/op_div.rb +3 -5
  39. data/lib/gloo/expr/op_minus.rb +3 -5
  40. data/lib/gloo/expr/op_mult.rb +3 -5
  41. data/lib/gloo/expr/op_plus.rb +5 -7
  42. data/lib/gloo/objs/basic/boolean.rb +63 -38
  43. data/lib/gloo/objs/basic/container.rb +40 -12
  44. data/lib/gloo/objs/basic/integer.rb +40 -16
  45. data/lib/gloo/objs/basic/script.rb +62 -38
  46. data/lib/gloo/objs/basic/string.rb +39 -15
  47. data/lib/gloo/objs/basic/text.rb +43 -20
  48. data/lib/gloo/objs/basic/untyped.rb +35 -10
  49. data/lib/gloo/objs/cli/colorize.rb +53 -23
  50. data/lib/gloo/objs/cli/confirm.rb +63 -29
  51. data/lib/gloo/objs/cli/prompt.rb +63 -29
  52. data/lib/gloo/objs/ctrl/each.rb +98 -60
  53. data/lib/gloo/objs/dev/git.rb +98 -64
  54. data/lib/gloo/objs/ror/erb.rb +81 -41
  55. data/lib/gloo/objs/ror/eval.rb +73 -31
  56. data/lib/gloo/objs/snd/play.rb +71 -0
  57. data/lib/gloo/objs/snd/say.rb +120 -0
  58. data/lib/gloo/objs/system/file_handle.rb +80 -48
  59. data/lib/gloo/objs/system/system.rb +84 -38
  60. data/lib/gloo/objs/web/http_get.rb +83 -46
  61. data/lib/gloo/objs/web/http_post.rb +69 -43
  62. data/lib/gloo/objs/web/slack.rb +89 -58
  63. data/lib/gloo/objs/web/teams.rb +88 -53
  64. data/lib/gloo/persist/file_loader.rb +81 -82
  65. data/lib/gloo/persist/file_saver.rb +12 -12
  66. data/lib/gloo/persist/file_storage.rb +15 -15
  67. data/lib/gloo/persist/line_splitter.rb +74 -0
  68. data/lib/gloo/persist/persist_man.rb +29 -29
  69. data/lib/gloo/utils/words.rb +2 -2
  70. data/lib/gloo/verbs/alert.rb +67 -16
  71. data/lib/gloo/verbs/beep.rb +70 -0
  72. data/lib/gloo/verbs/context.rb +61 -21
  73. data/lib/gloo/verbs/create.rb +52 -21
  74. data/lib/gloo/verbs/help.rb +177 -27
  75. data/lib/gloo/verbs/if.rb +54 -21
  76. data/lib/gloo/verbs/list.rb +55 -24
  77. data/lib/gloo/verbs/load.rb +46 -12
  78. data/lib/gloo/verbs/put.rb +90 -34
  79. data/lib/gloo/verbs/quit.rb +43 -12
  80. data/lib/gloo/verbs/run.rb +42 -11
  81. data/lib/gloo/verbs/save.rb +45 -10
  82. data/lib/gloo/verbs/show.rb +56 -22
  83. data/lib/gloo/verbs/tell.rb +44 -12
  84. data/lib/gloo/verbs/unless.rb +55 -21
  85. data/lib/gloo/verbs/version.rb +42 -12
  86. data/lib/run.rb +5 -5
  87. metadata +19 -12
@@ -11,19 +11,25 @@ module Gloo
11
11
  # Get text to display when the application is run
12
12
  # in HELP mode.
13
13
  def self.get_help_text
14
- str = "\nNAME\n\tgloo\n\n"
15
- str << "\nDESCRIPTION\n\tGloo scripting language. A scripting language built on ruby.\n"
16
- str << "\tMore information coming soon.\n\n"
17
- str << "\nSYNOPSIS\n\tgloo [global option] [file]\n\n"
18
- str << "\nGLOBAL OPTIONS\n"
19
- str << "\t--cli \t\t - Run in CLI mode\n"
20
- str << "\t--version \t - Show application version\n"
21
- str << "\t--help \t\t - Show this help page\n"
22
- str << "\n"
23
- return str
14
+ return <<~TEXT
15
+ NAME
16
+ \tgloo
17
+
18
+ DESCRIPTION
19
+ \tGloo scripting language. A scripting language built on ruby.
20
+ \tMore information coming soon.
21
+
22
+ SYNOPSIS
23
+ \tgloo [global option] [file]
24
+
25
+ GLOBAL OPTIONS
26
+ \t--cli \t\t - Run in CLI mode
27
+ \t--version \t - Show application version
28
+ \t--help \t\t - Show this help page
29
+
30
+ TEXT
24
31
  end
25
32
 
26
33
  end
27
34
  end
28
35
  end
29
-
@@ -8,9 +8,10 @@ module Gloo
8
8
  module App
9
9
  class Info
10
10
 
11
- VERSION = "0.3.0"
12
- APP_NAME = "Gloo"
11
+ VERSION = '0.4.0'.freeze
12
+ APP_NAME = 'Gloo'.freeze
13
13
 
14
+ # Get the application display title.
14
15
  def self.display_title
15
16
  return "#{APP_NAME}, version #{VERSION}"
16
17
  end
@@ -18,4 +19,3 @@ module Gloo
18
19
  end
19
20
  end
20
21
  end
21
-
@@ -12,46 +12,46 @@ module Gloo
12
12
  class Log
13
13
 
14
14
  attr_reader :logger, :quiet
15
-
15
+
16
16
  def initialize( quiet )
17
- f = File.join( $settings.log_path, "gloo.log" )
17
+ f = File.join( $settings.log_path, 'gloo.log' )
18
18
  @logger = Logger.new( f )
19
19
  @logger.level = Logger::DEBUG
20
20
  @quiet = quiet
21
21
  end
22
-
22
+
23
23
  # Show a message unless we're in quite mode.
24
- def show msg
24
+ def show( msg )
25
25
  puts msg unless @quiet
26
26
  end
27
-
28
- def debug msg
27
+
28
+ def debug( msg )
29
29
  @logger.debug msg
30
30
  end
31
31
 
32
- def info msg
32
+ def info( msg )
33
33
  @logger.info msg
34
34
  puts msg.blue unless @quiet
35
35
  end
36
36
 
37
- def warn msg
37
+ def warn( msg )
38
38
  @logger.warn msg
39
39
  puts msg.yellow unless @quiet
40
40
  end
41
41
 
42
- def error msg, e = nil
43
- if e
44
- @logger.error msg
45
- @logger.error e.message
46
- @logger.error e.backtrace
42
+ def error( msg, ex = nil, engine = nil )
43
+ engine&.heap&.error&.set_to msg
44
+ @logger.error msg
45
+ if ex
46
+ @logger.error ex.message
47
+ @logger.error ex.backtrace
47
48
  puts msg.red unless @quiet
48
- puts e.message.red unless @quiet
49
- puts e.backtrace unless @quiet
49
+ puts ex.message.red unless @quiet
50
+ puts ex.backtrace unless @quiet
50
51
  else
51
- @logger.error msg
52
52
  puts msg.red unless @quiet
53
53
  end
54
- end
54
+ end
55
55
 
56
56
  end
57
57
  end
@@ -7,19 +7,19 @@
7
7
  module Gloo
8
8
  module App
9
9
  class Mode
10
-
10
+
11
11
  EMBED = :embed # Run as embedded script processor
12
12
  CLI = :cli # Run in interactive (CLI) mode
13
13
  SCRIPT = :script # Run a script
14
14
  VERSION = :version # Show version information
15
15
  HELP = :help # Show the help screen
16
16
  TEST = :test # Running in Unit Test mode.
17
-
17
+
18
18
  # Get the default mode.
19
19
  def self.default_mode
20
20
  return EMBED
21
21
  end
22
-
22
+
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -15,90 +15,93 @@ module Gloo
15
15
  attr_reader :user_root, :log_path, :config_path, :project_path
16
16
  attr_reader :start_with, :list_indent
17
17
 
18
-
19
18
  # Load setting from the yml file.
20
- def initialize mode
19
+ def initialize( mode )
21
20
  @mode = mode
22
21
  init_root
23
22
  init_path_settings
24
23
  init_user_settings
25
24
  end
26
-
25
+
27
26
  def init_root
28
27
  if in_test_mode?
29
28
  path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
30
29
  path = File.dirname( File.dirname( path ) )
31
- path = File.join( path, "test", "gloo" )
30
+ path = File.join( path, 'test', 'gloo' )
32
31
  @user_root = path
33
32
  else
34
- @user_root = File.join( Dir.home, "gloo" )
33
+ @user_root = File.join( Dir.home, 'gloo' )
35
34
  end
36
35
  end
37
-
36
+
38
37
  # Are we in test mode?
39
38
  def in_test_mode?
40
39
  return @mode == 'TEST'
41
40
  end
42
41
 
42
+ # Get the project path for the current mode.
43
+ def project_path_for_mode( settings )
44
+ return File.join( @user_root, 'projects' ) if in_test_mode?
45
+
46
+ return settings[ 'gloo' ][ 'project_path' ]
47
+ end
48
+
43
49
  # Get the app's required directories.
44
50
  def init_path_settings
45
- Dir.mkdir( @user_root ) unless File.exists?( @user_root )
51
+ Dir.mkdir( @user_root ) unless File.exist?( @user_root )
46
52
 
47
- @log_path = File.join( @user_root, "logs" )
48
- Dir.mkdir( @log_path ) unless File.exists?( @log_path )
53
+ @log_path = File.join( @user_root, 'logs' )
54
+ Dir.mkdir( @log_path ) unless File.exist?( @log_path )
49
55
 
50
- @config_path = File.join( @user_root, "config" )
51
- Dir.mkdir( @config_path ) unless File.exists?( @config_path )
56
+ @config_path = File.join( @user_root, 'config' )
57
+ Dir.mkdir( @config_path ) unless File.exist?( @config_path )
52
58
  end
53
59
 
60
+ # Initialize the user settings for the currently
61
+ # running environment.
54
62
  def init_user_settings
55
63
  settings = get_settings
56
-
57
- if in_test_mode?
58
- @project_path = File.join( @user_root, "projects" )
59
- else
60
- @project_path = settings[ 'gloo' ][ 'project_path' ]
61
- end
64
+
65
+ @project_path = project_path_for_mode settings
62
66
  @start_with = settings[ 'gloo' ][ 'start_with' ]
63
67
  @list_indent = settings[ 'gloo' ][ 'list_indent' ]
64
68
  end
65
-
69
+
66
70
  # Get the app's required directories.
67
71
  def get_settings
68
- f = File.join( @config_path, "gloo.yml" )
69
- create_settings( f ) unless File.exists?( f )
70
- return YAML::load_file f
72
+ f = File.join( @config_path, 'gloo.yml' )
73
+ create_settings( f ) unless File.exist?( f )
74
+ return YAML.load_file f
71
75
  end
72
76
 
73
77
  # Create settings file.
74
- def create_settings f
75
- IO.write( f, get_default_settings )
78
+ def create_settings( file )
79
+ IO.write( file, get_default_settings )
76
80
  end
77
81
 
78
82
  # Get the value for default settings.
79
83
  def get_default_settings
80
- home_dir = Dir.home
81
- projects = File.join( @user_root, "projects" )
82
- str = <<TEXT
83
- gloo:
84
- project_path: #{projects}
85
- start_with:
86
- list_indent: 1
87
- TEXT
84
+ projects = File.join( @user_root, 'projects' )
85
+ str = <<~TEXT
86
+ gloo:
87
+ project_path: #{projects}
88
+ start_with:
89
+ list_indent: 1
90
+ TEXT
88
91
  return str
89
92
  end
90
93
 
91
94
  # Show the current application settings.
92
95
  def show
93
96
  puts "\nApplication Settings:".blue
94
- puts " User Root Path is here: ".yellow + @user_root.white
95
- puts " Projects directory: ".yellow + @projects.white
96
- puts " Startup with: ".yellow + @start_with.white
97
- puts " Indent in Listing: ".yellow + @list_indent.white
98
- puts ""
99
- puts " Screen Lines: ".yellow + "#{Settings.lines}".white
100
- puts " Page Size: ".yellow + "#{Settings.page_size}".white
101
- puts ""
97
+ puts ' User Root Path is here: '.yellow + @user_root.white
98
+ puts ' Projects directory: '.yellow + @projects.white
99
+ puts ' Startup with: '.yellow + @start_with.white
100
+ puts ' Indent in Listing: '.yellow + @list_indent.white
101
+ puts ''
102
+ puts ' Screen Lines: '.yellow + Settings.lines.to_s.white
103
+ puts ' Page Size: '.yellow + Settings.page_size.to_s.white
104
+ puts ''
102
105
  end
103
106
 
104
107
  # Get the number of lines on screen.
@@ -122,4 +125,4 @@ TEXT
122
125
 
123
126
  end
124
127
  end
125
- end
128
+ end
@@ -8,17 +8,17 @@
8
8
  module Gloo
9
9
  module Core
10
10
  class Baseo
11
-
11
+
12
12
  attr_accessor :name
13
-
13
+
14
14
  # Set up the object.
15
- def initialize()
16
- @name = ""
15
+ def initialize
16
+ @name = ''
17
17
  end
18
-
19
- #
18
+
19
+ #
20
20
  # The object type, suitable for display.
21
- #
21
+ #
22
22
  def type_display
23
23
  raise 'this method should be overriden'
24
24
  end
@@ -8,32 +8,32 @@ require 'singleton'
8
8
  module Gloo
9
9
  module Core
10
10
  class Dictionary
11
-
11
+
12
12
  include Singleton
13
-
13
+
14
14
  attr_reader :verbs, :objs
15
-
15
+
16
16
  # Set up the object dictionary.
17
- def initialize()
17
+ def initialize
18
18
  @verbs = {}
19
19
  @objs = {}
20
20
  @verb_references = []
21
21
  @obj_references = []
22
22
  end
23
-
23
+
24
24
  # Register a verb.
25
- def register_verb subclass
25
+ def register_verb( subclass )
26
26
  @verb_references << subclass
27
27
  end
28
-
28
+
29
29
  # Register an object type.
30
- def register_obj subclass
30
+ def register_obj( subclass )
31
31
  @obj_references << subclass
32
32
  end
33
33
 
34
34
  # Initialize verbs and objects in the dictionary.
35
35
  def init
36
- $log.debug "initializing dictionaries"
36
+ $log.debug 'initializing dictionaries'
37
37
  init_verbs
38
38
  init_objs
39
39
  end
@@ -42,60 +42,63 @@ module Gloo
42
42
  def init_objs
43
43
  $log.debug "initializing #{@obj_references.count} objects"
44
44
  @obj_references.each do |o|
45
- $log.debug o
45
+ $log.debug o
46
46
  @objs[ o.typename ] = o
47
47
  @objs[ o.short_typename ] = o
48
48
  end
49
49
  end
50
-
50
+
51
51
  # Is the given word an object type?
52
- def is_obj? word
52
+ def obj?( word )
53
53
  return false unless word
54
+
54
55
  return @objs.key?( word.downcase )
55
56
  end
56
-
57
+
57
58
  # Find the object type by name.
58
- def find_obj word
59
+ def find_obj( word )
59
60
  return nil unless word
60
- return nil unless is_obj?( word )
61
+ return nil unless obj?( word )
62
+
61
63
  return @objs[ word.downcase ]
62
64
  end
63
65
 
64
-
65
66
  # Init the list of verbs.
66
67
  def init_verbs
67
68
  $log.debug "initializing #{@verb_references.count} verbs"
68
69
  @verb_references.each do |v|
69
- $log.debug v
70
+ $log.debug v
70
71
  @verbs[ v.keyword ] = v
71
72
  @verbs[ v.keyword_shortcut ] = v
72
73
  # v.send( :new ).run
73
74
  end
74
75
  end
75
-
76
+
76
77
  # Is the given word a verb?
77
- def is_verb? word
78
+ def verb?( word )
78
79
  return false unless word
80
+
79
81
  return @verbs.key?( word.downcase )
80
82
  end
81
-
83
+
82
84
  # Find the verb by name.
83
- def find_verb verb
85
+ def find_verb( verb )
84
86
  return nil unless verb
85
- return nil unless is_verb?( verb )
87
+ return nil unless verb?( verb )
88
+
86
89
  return @verbs[ verb.downcase ]
87
90
  end
88
-
91
+
89
92
  # Get the list of verbs, sorted.
90
93
  def get_obj_types
91
- return @obj_references.sort{ |a,b| a.typename <=> b.typename }
94
+ return @obj_references.sort { |a, b| a.typename <=> b.typename }
92
95
  end
93
-
96
+
94
97
  # Get the list of verbs, sorted.
95
98
  def get_verbs
96
- return @verb_references.sort{ |a,b| a.keyword <=> b.keyword }
99
+ return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
97
100
  end
98
-
101
+
99
102
  end
100
103
  end
101
104
  end
@@ -0,0 +1,50 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # If the last command to run generated an error it will be here.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class Error
10
+
11
+ attr_accessor :value
12
+
13
+ # Set up the error object.
14
+ def initialize
15
+ @value = nil
16
+ @error_count = 0
17
+ end
18
+
19
+ # Set the value of error.
20
+ def set_to( new_value )
21
+ @error_count += 1
22
+ @value = new_value
23
+ end
24
+
25
+ # Clear out the error message.
26
+ def clear
27
+ @error_count = 0
28
+ @value = nil
29
+ end
30
+
31
+ # Start counting errors.
32
+ # We're looking to see if we get any new ones during
33
+ # a script or an immediate command.
34
+ def start_tracking
35
+ @error_count = 0
36
+ end
37
+
38
+ # Clear out error if we didn't add any new ones.
39
+ def clear_if_no_errors
40
+ self.clear if @error_count.zero?
41
+ end
42
+
43
+ # Get the string representation of the error.
44
+ def to_s
45
+ return @value.to_s
46
+ end
47
+
48
+ end
49
+ end
50
+ end