gloo 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +5 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +139 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/gloo +4 -0
  13. data/exe/o +4 -0
  14. data/gloo.gemspec +38 -0
  15. data/lib/gloo.rb +19 -0
  16. data/lib/gloo/app/args.rb +71 -0
  17. data/lib/gloo/app/engine.rb +158 -0
  18. data/lib/gloo/app/help.rb +29 -0
  19. data/lib/gloo/app/info.rb +21 -0
  20. data/lib/gloo/app/log.rb +58 -0
  21. data/lib/gloo/app/mode.rb +25 -0
  22. data/lib/gloo/app/settings.rb +125 -0
  23. data/lib/gloo/core/baseo.rb +28 -0
  24. data/lib/gloo/core/dictionary.rb +101 -0
  25. data/lib/gloo/core/event_manager.rb +46 -0
  26. data/lib/gloo/core/factory.rb +67 -0
  27. data/lib/gloo/core/gloo_system.rb +190 -0
  28. data/lib/gloo/core/heap.rb +42 -0
  29. data/lib/gloo/core/it.rb +30 -0
  30. data/lib/gloo/core/literal.rb +25 -0
  31. data/lib/gloo/core/obj.rb +222 -0
  32. data/lib/gloo/core/obj_finder.rb +35 -0
  33. data/lib/gloo/core/op.rb +33 -0
  34. data/lib/gloo/core/parser.rb +52 -0
  35. data/lib/gloo/core/pn.rb +134 -0
  36. data/lib/gloo/core/script.rb +37 -0
  37. data/lib/gloo/core/tokens.rb +123 -0
  38. data/lib/gloo/core/verb.rb +63 -0
  39. data/lib/gloo/expr/expression.rb +103 -0
  40. data/lib/gloo/expr/l_boolean.rb +29 -0
  41. data/lib/gloo/expr/l_integer.rb +29 -0
  42. data/lib/gloo/expr/l_string.rb +53 -0
  43. data/lib/gloo/expr/op_div.rb +20 -0
  44. data/lib/gloo/expr/op_minus.rb +20 -0
  45. data/lib/gloo/expr/op_mult.rb +20 -0
  46. data/lib/gloo/expr/op_plus.rb +22 -0
  47. data/lib/gloo/objs/basic/boolean.rb +113 -0
  48. data/lib/gloo/objs/basic/container.rb +50 -0
  49. data/lib/gloo/objs/basic/integer.rb +65 -0
  50. data/lib/gloo/objs/basic/script.rb +101 -0
  51. data/lib/gloo/objs/basic/string.rb +65 -0
  52. data/lib/gloo/objs/basic/text.rb +64 -0
  53. data/lib/gloo/objs/basic/untyped.rb +42 -0
  54. data/lib/gloo/objs/cli/colorize.rb +73 -0
  55. data/lib/gloo/objs/cli/confirm.rb +92 -0
  56. data/lib/gloo/objs/cli/prompt.rb +92 -0
  57. data/lib/gloo/objs/ctrl/each.rb +212 -0
  58. data/lib/gloo/objs/dev/git.rb +112 -0
  59. data/lib/gloo/objs/ror/erb.rb +109 -0
  60. data/lib/gloo/objs/ror/eval.rb +92 -0
  61. data/lib/gloo/objs/system/file_handle.rb +86 -0
  62. data/lib/gloo/objs/system/system.rb +120 -0
  63. data/lib/gloo/objs/web/http_get.rb +128 -0
  64. data/lib/gloo/objs/web/http_post.rb +127 -0
  65. data/lib/gloo/objs/web/slack.rb +126 -0
  66. data/lib/gloo/objs/web/teams.rb +117 -0
  67. data/lib/gloo/persist/file_loader.rb +171 -0
  68. data/lib/gloo/persist/file_saver.rb +43 -0
  69. data/lib/gloo/persist/file_storage.rb +43 -0
  70. data/lib/gloo/persist/persist_man.rb +90 -0
  71. data/lib/gloo/utils/words.rb +19 -0
  72. data/lib/gloo/verbs/alert.rb +42 -0
  73. data/lib/gloo/verbs/context.rb +52 -0
  74. data/lib/gloo/verbs/create.rb +52 -0
  75. data/lib/gloo/verbs/help.rb +69 -0
  76. data/lib/gloo/verbs/if.rb +56 -0
  77. data/lib/gloo/verbs/list.rb +85 -0
  78. data/lib/gloo/verbs/load.rb +39 -0
  79. data/lib/gloo/verbs/put.rb +62 -0
  80. data/lib/gloo/verbs/quit.rb +40 -0
  81. data/lib/gloo/verbs/run.rb +46 -0
  82. data/lib/gloo/verbs/save.rb +37 -0
  83. data/lib/gloo/verbs/show.rb +55 -0
  84. data/lib/gloo/verbs/tell.rb +47 -0
  85. data/lib/gloo/verbs/unless.rb +56 -0
  86. data/lib/gloo/verbs/version.rb +37 -0
  87. data/lib/run.rb +13 -0
  88. metadata +254 -0
@@ -0,0 +1,158 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The Gloo Script Engine.
5
+ #
6
+
7
+ require 'tty-prompt'
8
+ require 'tty-cursor'
9
+ require 'colorize'
10
+
11
+ module Gloo
12
+ module App
13
+ class Engine
14
+
15
+ attr_reader :args, :mode, :running
16
+ attr_reader :dictionary, :parser, :heap, :factory
17
+ attr_accessor :last_cmd, :persist_man, :event_manager
18
+
19
+ # Set up the engine with basic elements.
20
+ def initialize( params = [] )
21
+ $engine = self
22
+ @args = Args.new( params )
23
+ $settings = Settings.new( ENV[ 'GLOO_ENV' ] )
24
+ $log = Log.new( @args.quiet? )
25
+ $prompt = TTY::Prompt.new
26
+ $log.debug "engine intialized..."
27
+ end
28
+
29
+ # Start the engine.
30
+ def start
31
+ $log.debug "starting the engine..."
32
+ $log.debug Info.display_title
33
+ @mode = @args.detect_mode
34
+ @running = true
35
+
36
+ @dictionary = Gloo::Core::Dictionary.instance
37
+ @dictionary.init
38
+ @parser = Gloo::Core::Parser.new
39
+ @heap = Gloo::Core::Heap.new
40
+ @factory = Gloo::Core::Factory.new
41
+ @persist_man = Gloo::Persist::PersistMan.new
42
+ @event_manager = Gloo::Core::EventManager.new
43
+
44
+ run_mode
45
+ end
46
+
47
+ # Run the selected mode.
48
+ def run_mode
49
+ if @mode == Mode::VERSION
50
+ run_version
51
+ elsif @mode == Mode::HELP
52
+ run_help
53
+ elsif @mode == Mode::SCRIPT
54
+ run_files
55
+ else
56
+ run
57
+ end
58
+ end
59
+
60
+ # Run files specified on the CLI.
61
+ # Then quit.
62
+ def run_files
63
+ @args.files.each do |f|
64
+ @persist_man.load( f )
65
+ end
66
+
67
+ quit
68
+ end
69
+
70
+ # Run
71
+ def run
72
+ # Open default files
73
+ self.open_start_file
74
+
75
+ # TODO: open any files specifed in args
76
+
77
+ unless @mode == Mode::SCRIPT || @args.quiet?
78
+ @cursor = TTY::Cursor
79
+ self.loop
80
+ end
81
+
82
+ quit
83
+ end
84
+
85
+ # Get the setting for the start_with file and open it.
86
+ def open_start_file
87
+ name = $settings.start_with
88
+ @persist_man.load( name ) if name
89
+ end
90
+
91
+ # Prompt for the next command.
92
+ def prompt_cmd
93
+ dt = DateTime.now
94
+ d = dt.strftime( '%Y.%m.%d' )
95
+ t = dt.strftime( '%I:%M:%S' )
96
+
97
+ @last_cmd = $prompt.ask( "#{d.yellow} #{t.white} >" )
98
+ end
99
+
100
+ # Is the last command entered blank?
101
+ def last_cmd_blank?
102
+ return true if @last_cmd.nil?
103
+ return true if @last_cmd.strip.empty?
104
+ end
105
+
106
+ # Prompt, Get input, process.
107
+ def loop
108
+ while @running
109
+ prompt_cmd
110
+ process_cmd
111
+ end
112
+ end
113
+
114
+ # Process the command.
115
+ def process_cmd
116
+ if last_cmd_blank?
117
+ clear_screen
118
+ return
119
+ end
120
+
121
+ @immediate = @parser.parse_immediate @last_cmd
122
+ @immediate.run if @immediate
123
+ end
124
+
125
+ # Request the engine to stop running.
126
+ def stop_running
127
+ @running = false
128
+ end
129
+
130
+ # Do any clean up and quit.
131
+ def quit
132
+ $log.debug "quitting..."
133
+ end
134
+
135
+ # Show the version information and then quit.
136
+ def run_version
137
+ puts Info.display_title unless @args.quiet?
138
+ quit
139
+ end
140
+
141
+ # Show the help information and then quit.
142
+ def run_help keep_running=false
143
+ unless @args.quiet?
144
+ puts Info.display_title
145
+ puts Help.get_help_text
146
+ end
147
+ quit unless keep_running
148
+ end
149
+
150
+ # Clear the screen.
151
+ def clear_screen
152
+ print @cursor.clear_screen
153
+ print @cursor.move_to( 0, 0 )
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,29 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Help system.
5
+ #
6
+
7
+ module Gloo
8
+ module App
9
+ class Help
10
+
11
+ # Get text to display when the application is run
12
+ # in HELP mode.
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
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,21 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Application information such as Version and public name.
5
+ #
6
+
7
+ module Gloo
8
+ module App
9
+ class Info
10
+
11
+ VERSION = "0.3.0"
12
+ APP_NAME = "Gloo"
13
+
14
+ def self.display_title
15
+ return "#{APP_NAME}, version #{VERSION}"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,58 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Application Logging wrapper.
5
+ #
6
+ require 'active_support'
7
+ require 'colorize'
8
+ require 'colorized_string'
9
+
10
+ module Gloo
11
+ module App
12
+ class Log
13
+
14
+ attr_reader :logger, :quiet
15
+
16
+ def initialize( quiet )
17
+ f = File.join( $settings.log_path, "gloo.log" )
18
+ @logger = Logger.new( f )
19
+ @logger.level = Logger::DEBUG
20
+ @quiet = quiet
21
+ end
22
+
23
+ # Show a message unless we're in quite mode.
24
+ def show msg
25
+ puts msg unless @quiet
26
+ end
27
+
28
+ def debug msg
29
+ @logger.debug msg
30
+ end
31
+
32
+ def info msg
33
+ @logger.info msg
34
+ puts msg.blue unless @quiet
35
+ end
36
+
37
+ def warn msg
38
+ @logger.warn msg
39
+ puts msg.yellow unless @quiet
40
+ end
41
+
42
+ def error msg, e = nil
43
+ if e
44
+ @logger.error msg
45
+ @logger.error e.message
46
+ @logger.error e.backtrace
47
+ puts msg.red unless @quiet
48
+ puts e.message.red unless @quiet
49
+ puts e.backtrace unless @quiet
50
+ else
51
+ @logger.error msg
52
+ puts msg.red unless @quiet
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Mode the Application is running in.
5
+ #
6
+
7
+ module Gloo
8
+ module App
9
+ class Mode
10
+
11
+ EMBED = :embed # Run as embedded script processor
12
+ CLI = :cli # Run in interactive (CLI) mode
13
+ SCRIPT = :script # Run a script
14
+ VERSION = :version # Show version information
15
+ HELP = :help # Show the help screen
16
+ TEST = :test # Running in Unit Test mode.
17
+
18
+ # Get the default mode.
19
+ def self.default_mode
20
+ return EMBED
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,125 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Application and user settings.
5
+ #
6
+
7
+ require 'yaml'
8
+ require 'tty-screen'
9
+ require 'colorize'
10
+
11
+ module Gloo
12
+ module App
13
+ class Settings
14
+
15
+ attr_reader :user_root, :log_path, :config_path, :project_path
16
+ attr_reader :start_with, :list_indent
17
+
18
+
19
+ # Load setting from the yml file.
20
+ def initialize mode
21
+ @mode = mode
22
+ init_root
23
+ init_path_settings
24
+ init_user_settings
25
+ end
26
+
27
+ def init_root
28
+ if in_test_mode?
29
+ path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
30
+ path = File.dirname( File.dirname( path ) )
31
+ path = File.join( path, "test", "gloo" )
32
+ @user_root = path
33
+ else
34
+ @user_root = File.join( Dir.home, "gloo" )
35
+ end
36
+ end
37
+
38
+ # Are we in test mode?
39
+ def in_test_mode?
40
+ return @mode == 'TEST'
41
+ end
42
+
43
+ # Get the app's required directories.
44
+ def init_path_settings
45
+ Dir.mkdir( @user_root ) unless File.exists?( @user_root )
46
+
47
+ @log_path = File.join( @user_root, "logs" )
48
+ Dir.mkdir( @log_path ) unless File.exists?( @log_path )
49
+
50
+ @config_path = File.join( @user_root, "config" )
51
+ Dir.mkdir( @config_path ) unless File.exists?( @config_path )
52
+ end
53
+
54
+ def init_user_settings
55
+ 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
62
+ @start_with = settings[ 'gloo' ][ 'start_with' ]
63
+ @list_indent = settings[ 'gloo' ][ 'list_indent' ]
64
+ end
65
+
66
+ # Get the app's required directories.
67
+ 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
71
+ end
72
+
73
+ # Create settings file.
74
+ def create_settings f
75
+ IO.write( f, get_default_settings )
76
+ end
77
+
78
+ # Get the value for default settings.
79
+ 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
88
+ return str
89
+ end
90
+
91
+ # Show the current application settings.
92
+ def show
93
+ 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 ""
102
+ end
103
+
104
+ # Get the number of lines on screen.
105
+ def self.lines
106
+ TTY::Screen.rows
107
+ end
108
+
109
+ def self.cols
110
+ TTY::Screen.cols
111
+ end
112
+
113
+ # Get the default page size.
114
+ def self.page_size
115
+ Settings.lines - 3
116
+ end
117
+
118
+ # How many lines should we use for a preview?
119
+ def self.preview_lines
120
+ return 7
121
+ end
122
+
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,28 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An abstract base object.
5
+ # All objects and verbs derive from this.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Baseo
11
+
12
+ attr_accessor :name
13
+
14
+ # Set up the object.
15
+ def initialize()
16
+ @name = ""
17
+ end
18
+
19
+ #
20
+ # The object type, suitable for display.
21
+ #
22
+ def type_display
23
+ raise 'this method should be overriden'
24
+ end
25
+
26
+ end
27
+ end
28
+ end