gloo 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/Gemfile.lock +32 -28
  4. data/LICENSE.txt +1 -1
  5. data/gloo.gemspec +11 -6
  6. data/lib/VERSION +1 -1
  7. data/lib/dependencies.rb +4 -4
  8. data/lib/gloo/app/info.rb +3 -1
  9. data/lib/gloo/app/log.rb +1 -29
  10. data/lib/gloo/app/platform.rb +142 -0
  11. data/lib/gloo/objs/cli/banner.rb +2 -2
  12. data/lib/gloo/objs/cli/bar.rb +4 -4
  13. data/lib/gloo/objs/cli/colorize.rb +3 -3
  14. data/lib/gloo/objs/cli/confirm.rb +3 -3
  15. data/lib/gloo/objs/cli/menu.rb +9 -9
  16. data/lib/gloo/objs/cli/menu_item.rb +2 -2
  17. data/lib/gloo/objs/cli/pastel.rb +2 -2
  18. data/lib/gloo/objs/cli/prompt.rb +4 -4
  19. data/lib/gloo/objs/cli/select.rb +4 -4
  20. data/lib/gloo/objs/dev/git.rb +7 -7
  21. data/lib/gloo/objs/dev/stats.rb +8 -5
  22. data/lib/gloo/objs/snd/play.rb +1 -1
  23. data/lib/gloo/objs/snd/say.rb +2 -2
  24. data/lib/gloo/objs/system/file_handle.rb +9 -9
  25. data/lib/gloo/objs/system/ssh_exec.rb +3 -3
  26. data/lib/gloo/objs/system/system.rb +2 -2
  27. data/lib/gloo/verbs/alert.rb +7 -7
  28. data/lib/gloo/verbs/beep.rb +1 -1
  29. data/lib/gloo/verbs/cls.rb +2 -2
  30. data/lib/gloo.rb +5 -1
  31. data/lib/run.rb +5 -1
  32. metadata +39 -145
  33. data/lib/gloo/app/args.rb +0 -112
  34. data/lib/gloo/app/engine.rb +0 -230
  35. data/lib/gloo/app/help.rb +0 -156
  36. data/lib/gloo/app/mode.rb +0 -27
  37. data/lib/gloo/app/settings.rb +0 -186
  38. data/lib/gloo/convert/converter.rb +0 -35
  39. data/lib/gloo/convert/string_to_datetime.rb +0 -21
  40. data/lib/gloo/convert/string_to_decimal.rb +0 -20
  41. data/lib/gloo/convert/string_to_integer.rb +0 -20
  42. data/lib/gloo/core/baseo.rb +0 -30
  43. data/lib/gloo/core/dictionary.rb +0 -181
  44. data/lib/gloo/core/error.rb +0 -61
  45. data/lib/gloo/core/event_manager.rb +0 -44
  46. data/lib/gloo/core/factory.rb +0 -210
  47. data/lib/gloo/core/gloo_system.rb +0 -266
  48. data/lib/gloo/core/heap.rb +0 -52
  49. data/lib/gloo/core/here.rb +0 -36
  50. data/lib/gloo/core/it.rb +0 -36
  51. data/lib/gloo/core/literal.rb +0 -30
  52. data/lib/gloo/core/obj.rb +0 -303
  53. data/lib/gloo/core/obj_finder.rb +0 -30
  54. data/lib/gloo/core/op.rb +0 -40
  55. data/lib/gloo/core/parser.rb +0 -59
  56. data/lib/gloo/core/pn.rb +0 -188
  57. data/lib/gloo/core/tokens.rb +0 -165
  58. data/lib/gloo/core/verb.rb +0 -86
  59. data/lib/gloo/exec/action.rb +0 -48
  60. data/lib/gloo/exec/dispatch.rb +0 -40
  61. data/lib/gloo/exec/exec_env.rb +0 -74
  62. data/lib/gloo/exec/runner.rb +0 -45
  63. data/lib/gloo/exec/script.rb +0 -49
  64. data/lib/gloo/exec/stack.rb +0 -78
  65. data/lib/gloo/expr/expression.rb +0 -118
  66. data/lib/gloo/expr/l_boolean.rb +0 -36
  67. data/lib/gloo/expr/l_decimal.rb +0 -39
  68. data/lib/gloo/expr/l_integer.rb +0 -37
  69. data/lib/gloo/expr/l_string.rb +0 -58
  70. data/lib/gloo/expr/op_div.rb +0 -22
  71. data/lib/gloo/expr/op_minus.rb +0 -22
  72. data/lib/gloo/expr/op_mult.rb +0 -22
  73. data/lib/gloo/expr/op_plus.rb +0 -24
  74. data/lib/gloo/objs/basic/alias.rb +0 -78
  75. data/lib/gloo/objs/basic/boolean.rb +0 -120
  76. data/lib/gloo/objs/basic/container.rb +0 -76
  77. data/lib/gloo/objs/basic/decimal.rb +0 -76
  78. data/lib/gloo/objs/basic/integer.rb +0 -73
  79. data/lib/gloo/objs/basic/script.rb +0 -99
  80. data/lib/gloo/objs/basic/string.rb +0 -77
  81. data/lib/gloo/objs/basic/text.rb +0 -87
  82. data/lib/gloo/objs/basic/untyped.rb +0 -41
  83. data/lib/gloo/objs/ctrl/each.rb +0 -279
  84. data/lib/gloo/objs/ctrl/repeat.rb +0 -108
  85. data/lib/gloo/objs/data/markdown.rb +0 -84
  86. data/lib/gloo/objs/data/mysql.rb +0 -192
  87. data/lib/gloo/objs/data/query.rb +0 -176
  88. data/lib/gloo/objs/data/sqlite.rb +0 -159
  89. data/lib/gloo/objs/data/table.rb +0 -140
  90. data/lib/gloo/objs/dt/date.rb +0 -50
  91. data/lib/gloo/objs/dt/datetime.rb +0 -62
  92. data/lib/gloo/objs/dt/time.rb +0 -50
  93. data/lib/gloo/objs/ror/erb.rb +0 -116
  94. data/lib/gloo/objs/ror/eval.rb +0 -107
  95. data/lib/gloo/objs/web/http_get.rb +0 -159
  96. data/lib/gloo/objs/web/http_post.rb +0 -183
  97. data/lib/gloo/objs/web/json.rb +0 -135
  98. data/lib/gloo/objs/web/slack.rb +0 -130
  99. data/lib/gloo/objs/web/teams.rb +0 -117
  100. data/lib/gloo/objs/web/uri.rb +0 -148
  101. data/lib/gloo/persist/file_loader.rb +0 -191
  102. data/lib/gloo/persist/file_saver.rb +0 -49
  103. data/lib/gloo/persist/file_storage.rb +0 -45
  104. data/lib/gloo/persist/line_splitter.rb +0 -81
  105. data/lib/gloo/persist/persist_man.rb +0 -120
  106. data/lib/gloo/utils/format.rb +0 -21
  107. data/lib/gloo/utils/stats.rb +0 -205
  108. data/lib/gloo/utils/words.rb +0 -19
  109. data/lib/gloo/verbs/context.rb +0 -62
  110. data/lib/gloo/verbs/create.rb +0 -68
  111. data/lib/gloo/verbs/execute.rb +0 -56
  112. data/lib/gloo/verbs/help.rb +0 -264
  113. data/lib/gloo/verbs/if.rb +0 -92
  114. data/lib/gloo/verbs/list.rb +0 -98
  115. data/lib/gloo/verbs/load.rb +0 -45
  116. data/lib/gloo/verbs/move.rb +0 -89
  117. data/lib/gloo/verbs/put.rb +0 -94
  118. data/lib/gloo/verbs/quit.rb +0 -40
  119. data/lib/gloo/verbs/run.rb +0 -75
  120. data/lib/gloo/verbs/save.rb +0 -39
  121. data/lib/gloo/verbs/show.rb +0 -64
  122. data/lib/gloo/verbs/tell.rb +0 -79
  123. data/lib/gloo/verbs/unless.rb +0 -92
  124. data/lib/gloo/verbs/version.rb +0 -37
  125. data/lib/gloo/verbs/wait.rb +0 -42
data/lib/gloo/app/args.rb DELETED
@@ -1,112 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Arguments (parameters) used to specify functionality.
5
- # These might have come from the CLI or as parameters
6
- # in the constructor.
7
- #
8
- require 'active_support'
9
- require 'colorize'
10
-
11
- module Gloo
12
- module App
13
- class Args
14
-
15
- QUIET = 'quiet'.freeze
16
- GLOO_ENV = 'GLOO_ENV'.freeze
17
-
18
- attr_reader :switches, :files
19
-
20
- #
21
- # Create arguments and setup.
22
- #
23
- def initialize( params = [] )
24
- @switches = []
25
- @files = []
26
-
27
- params.each { |o| process_one_arg( o ) }
28
- ARGV.each { |o| process_one_arg( o ) }
29
- end
30
-
31
- #
32
- # Was the --quiet arg passed?
33
- #
34
- def quiet?
35
- return @switches.include?( QUIET )
36
- end
37
-
38
- #
39
- # Is the version switch set?
40
- #
41
- def version?
42
- @switches.include?( Gloo::App::Mode::VERSION.to_s )
43
- end
44
-
45
- #
46
- # Is the help switch set?
47
- #
48
- def help?
49
- @switches.include?( Gloo::App::Mode::HELP.to_s )
50
- end
51
-
52
- #
53
- # Is the cli switch set?
54
- #
55
- def cli?
56
- @switches.include?( Gloo::App::Mode::CLI.to_s )
57
- end
58
-
59
- #
60
- # Is the embed switch set?
61
- #
62
- def embed?
63
- @switches.include?( Gloo::App::Mode::EMBED.to_s )
64
- end
65
-
66
- #
67
- # Detect the mode to be run in.
68
- # Start by seeing if a mode is specified.
69
- # Then look for the presence of files.
70
- # Then finally use the default: embedded mode.
71
- #
72
- def detect_mode
73
- mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s
74
- Mode::TEST
75
- elsif version?
76
- Mode::VERSION
77
- elsif help?
78
- Mode::HELP
79
- elsif cli?
80
- Mode::CLI
81
- elsif embed?
82
- Mode::EMBED
83
- elsif @files.count.positive?
84
- Mode::SCRIPT
85
- else
86
- Mode.default_mode
87
- end
88
- $log.debug "running in #{mode} mode"
89
-
90
- return mode
91
- end
92
-
93
- # ---------------------------------------------------------------------
94
- # Private
95
- # ---------------------------------------------------------------------
96
-
97
- private
98
-
99
- #
100
- # Process one argument or parameter.
101
- #
102
- def process_one_arg( arg )
103
- if arg.start_with? '--'
104
- switches << arg[ 2..-1 ]
105
- else
106
- files << arg
107
- end
108
- end
109
-
110
- end
111
- end
112
- end
@@ -1,230 +0,0 @@
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
- # The Engine aggregates all the elements needed to run gloo.
6
- # The Engine runs the main event loop and delegates processing
7
- # to the relevant element.
8
- #
9
-
10
- require 'tty-prompt'
11
- require 'tty-cursor'
12
- require 'colorize'
13
-
14
- module Gloo
15
- module App
16
- class Engine
17
-
18
- attr_reader :args, :mode, :running,
19
- :dictionary, :parser, :heap, :factory
20
- attr_accessor :last_cmd, :persist_man, :event_manager,
21
- :exec_env, :help, :converter
22
-
23
- #
24
- # Set up the engine with basic elements.
25
- #
26
- def initialize( params = [] )
27
- $engine = self
28
- @args = Args.new( params )
29
- $settings = Settings.new( ENV[ 'GLOO_ENV' ] )
30
- $log = Log.new( @args.quiet? )
31
- $prompt = TTY::Prompt.new
32
- $log.debug 'engine intialized...'
33
- end
34
-
35
- #
36
- # Start the engine.
37
- # Load object and verb definitions and setup engine elements.
38
- #
39
- def start
40
- $log.debug 'starting the engine...'
41
- $log.debug Info.display_title
42
- @mode = @args.detect_mode
43
- @running = true
44
-
45
- @dictionary = Gloo::Core::Dictionary.instance
46
- @dictionary.init
47
- @parser = Gloo::Core::Parser.new
48
- @heap = Gloo::Core::Heap.new
49
- @factory = Gloo::Core::Factory.new
50
- @persist_man = Gloo::Persist::PersistMan.new
51
- @event_manager = Gloo::Core::EventManager.new
52
-
53
- @exec_env = Gloo::Exec::ExecEnv.new
54
- @help = Gloo::App::Help.new
55
- @converter = Gloo::Convert::Converter.new
56
-
57
- $log.debug 'the engine has started'
58
- run_mode
59
- end
60
-
61
- # ---------------------------------------------------------------------
62
- # Run
63
- # ---------------------------------------------------------------------
64
-
65
- #
66
- # Run gloo in the selected mode.
67
- #
68
- def run_mode
69
- $log.debug "running gloo in #{@mode} mode"
70
-
71
- if @mode == Mode::VERSION
72
- run_version
73
- elsif @mode == Mode::HELP
74
- show_help_and_quit
75
- elsif @mode == Mode::SCRIPT
76
- run_files
77
- else
78
- run
79
- end
80
- end
81
-
82
- #
83
- # Run files specified on the CLI.
84
- # Then quit.
85
- #
86
- def run_files
87
- @args.files.each { |f| @persist_man.load( f ) }
88
- quit
89
- end
90
-
91
- #
92
- # Run in interactive mode.
93
- #
94
- def run
95
- # Open default file(s)
96
- self.open_start_file
97
-
98
- # TODO: open any files specifed in args
99
-
100
- unless @mode == Mode::SCRIPT || @args.quiet?
101
- @cursor = TTY::Cursor
102
- self.loop
103
- end
104
-
105
- quit
106
- end
107
-
108
- #
109
- # Get the setting for the start_with file and open it.
110
- #
111
- def open_start_file
112
- name = $settings.start_with
113
- @persist_man.load( name ) if name
114
- end
115
-
116
- #
117
- # Prompt for the next command.
118
- #
119
- def prompt_cmd
120
- @last_cmd = $prompt.ask( default_prompt )
121
- end
122
-
123
- #
124
- # Get the default prompt text.
125
- #
126
- def default_prompt
127
- dt = DateTime.now
128
- d = dt.strftime( '%Y.%m.%d' )
129
- t = dt.strftime( '%I:%M:%S' )
130
- return "#{'gloo'.blue} #{d.yellow} #{t.white} >"
131
- end
132
-
133
- #
134
- # Is the last command entered blank?
135
- #
136
- def last_cmd_blank?
137
- return true if @last_cmd.nil?
138
- return true if @last_cmd.strip.empty?
139
-
140
- return false
141
- end
142
-
143
- #
144
- # Prompt, Get input, process.
145
- #
146
- def loop
147
- while @running
148
- prompt_cmd
149
- process_cmd
150
- end
151
- end
152
-
153
- #
154
- # Process the command.
155
- #
156
- def process_cmd
157
- if last_cmd_blank?
158
- clear_screen
159
- return
160
- end
161
-
162
- @parser.run @last_cmd
163
- end
164
-
165
- #
166
- # Request the engine to stop running.
167
- #
168
- def stop_running
169
- @running = false
170
- end
171
-
172
- #
173
- # Do any clean up and quit.
174
- #
175
- def quit
176
- $log.debug 'quitting...'
177
- end
178
-
179
- # ---------------------------------------------------------------------
180
- # Helpers
181
- # ---------------------------------------------------------------------
182
-
183
- #
184
- # Show the version information and then quit.
185
- #
186
- def run_version
187
- puts Info.display_title unless @args.quiet?
188
- quit
189
- end
190
-
191
- #
192
- # Show the help information and then quit.
193
- #
194
- def show_help_and_quit
195
- @help.show_app_help
196
- quit
197
- end
198
-
199
- #
200
- # Clear the screen.
201
- #
202
- def clear_screen
203
- @cursor ||= TTY::Cursor
204
- print @cursor.clear_screen
205
- print @cursor.move_to( 0, 0 )
206
- end
207
-
208
- # ---------------------------------------------------------------------
209
- # Error Handling
210
- # ---------------------------------------------------------------------
211
-
212
- #
213
- # Did the last command result in an error?
214
- #
215
- def error?
216
- return !@heap.error.value.nil?
217
- end
218
-
219
- #
220
- # Report an error.
221
- # Write it to the log and set the heap error value.
222
- #
223
- def err( msg )
224
- $log.error msg
225
- self.heap.error.set_to msg
226
- end
227
-
228
- end
229
- end
230
- end
data/lib/gloo/app/help.rb DELETED
@@ -1,156 +0,0 @@
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
- require 'tty-markdown'
8
- require 'tty-pager'
9
-
10
- module Gloo
11
- module App
12
- class Help
13
-
14
- APPLICATION = 'application'.freeze
15
-
16
- attr_accessor :topics
17
-
18
- #
19
- # Set up the help system.
20
- # We won't load help topics until we know we need them.
21
- #
22
- def initialize
23
- @topics = nil
24
- end
25
-
26
- #
27
- # Show application help.
28
- # This is the what is shown when help is run from the CLI.
29
- #
30
- def show_app_help
31
- puts Info.display_title unless $engine.args.quiet?
32
- self.show_topic APPLICATION
33
- end
34
-
35
- #
36
- # Check to see if there is a topic by the given name.
37
- #
38
- def topic?( name )
39
- lazy_load_index
40
-
41
- return @topics.key?( name )
42
- end
43
-
44
- #
45
- # Is the current topic Markdown?
46
- #
47
- def topic_is_md?( name )
48
- lazy_load_index
49
-
50
- topic_file = @topics[ name ]
51
- return topic_file.end_with? '.md'
52
- end
53
-
54
- #
55
- # Show a help topic, optionally paginaged.
56
- # If the content of the help page fits on a single
57
- # screen, it won't paginate.
58
- #
59
- def page_topic( topic )
60
- return if $engine.args.quiet?
61
-
62
- data = self.get_topic_data( topic )
63
- page = data.lines.count > Settings.page_size
64
- if topic_is_md?( topic )
65
- show_markdown_data( data, page )
66
- else
67
- show_text_data( data, page )
68
- end
69
- end
70
-
71
- #
72
- # Show a help topic.
73
- #
74
- def show_topic( topic )
75
- return if $engine.args.quiet?
76
-
77
- data = self.get_topic_data( topic )
78
- if topic_is_md?( topic )
79
- show_markdown_data data
80
- else
81
- show_text_data data
82
- end
83
- end
84
-
85
- #
86
- # Show the markdown data.
87
- #
88
- def show_text_data( data, page = false )
89
- if page
90
- pager = TTY::Pager.new
91
- pager.page( data )
92
- else
93
- puts data.white
94
- puts
95
- end
96
- end
97
-
98
- #
99
- # Show the markdown data.
100
- #
101
- def show_markdown_data( data, page = false )
102
- md = TTY::Markdown.parse data
103
-
104
- if page
105
- pager = TTY::Pager.new
106
- pager.page( md )
107
- else
108
- puts md
109
- puts
110
- end
111
- end
112
-
113
- #
114
- # Get topic data.
115
- #
116
- def get_topic_data( topic )
117
- lazy_load_index
118
-
119
- topic_file = @topics[ topic ]
120
- return nil unless topic_file
121
-
122
- File.read topic_file
123
- end
124
-
125
- #
126
- # Lazy load topic index.
127
- # We'll only load the index the first time a help topic
128
- # is requested. After that we'll use the cached index.
129
- #
130
- def lazy_load_index
131
- return if @topics
132
-
133
- @topics = {}
134
- $log.debug 'loading help file index...'
135
-
136
- pn = File.dirname( File.absolute_path( __FILE__ ) )
137
- pn = File.dirname( pn )
138
-
139
- root = File.join( pn, 'help', '**/*.txt' )
140
- Dir.glob( root ).each do |txt_file|
141
- key = File.basename( txt_file, '.txt' )
142
- @topics[ key ] = txt_file
143
- end
144
-
145
- root = File.join( pn, 'help', '**/*.md' )
146
- Dir.glob( root ).each do |md_file|
147
- key = File.basename( md_file, '.md' )
148
- @topics[ key ] = md_file
149
- end
150
-
151
- $log.debug "Found #{@topics.count} help files"
152
- end
153
-
154
- end
155
- end
156
- end
data/lib/gloo/app/mode.rb DELETED
@@ -1,27 +0,0 @@
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
- #
19
- # Get the default mode.
20
- #
21
- def self.default_mode
22
- return EMBED
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,186 +0,0 @@
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
- :start_with, :list_indent, :tmp_path,
17
- :debug_path, :debug
18
-
19
- #
20
- # Load setting from the yml file.
21
- # The mode parameter is used to determine if we are running in TEST.
22
- #
23
- def initialize( mode )
24
- @mode = mode
25
- init_root
26
- init_path_settings
27
- init_user_settings
28
- end
29
-
30
- #
31
- # Are we in test mode?
32
- #
33
- def in_test_mode?
34
- return @mode == 'TEST'
35
- end
36
-
37
- #
38
- # Get the project path for the current mode.
39
- #
40
- def project_path_for_mode( settings )
41
- return File.join( @user_root, 'projects' ) if in_test_mode?
42
-
43
- return settings[ 'gloo' ][ 'project_path' ]
44
- end
45
-
46
- #
47
- # Show the current application settings.
48
- # Can be seen in app with 'help settings'
49
- #
50
- def show
51
- puts "\nApplication Settings:".blue
52
- puts ' Startup with: '.yellow + @start_with.white
53
- puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
54
- puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
55
- puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
56
- puts ''
57
- self.show_paths
58
- puts ''
59
- end
60
-
61
- #
62
- # Show path settings
63
- #
64
- def show_paths
65
- puts ' User Root Path is here: '.yellow + @user_root.white
66
- puts ' Projects Path: '.yellow + @project_path.white
67
- puts ' Tmp Path: '.yellow + @tmp_path.white
68
- puts ' Debug Path: '.yellow + @debug_path.white
69
- end
70
-
71
- #
72
- # Get the number of vertical lines on screen.
73
- #
74
- def self.lines
75
- TTY::Screen.rows
76
- end
77
-
78
- #
79
- # Get the number of horizontal columns on screen.
80
- #
81
- def self.cols
82
- TTY::Screen.cols
83
- end
84
-
85
- #
86
- # Get the default page size.
87
- # This is the number of lines of text we can show.
88
- #
89
- def self.page_size
90
- Settings.lines - 3
91
- end
92
-
93
- #
94
- # How many lines should we use for a preview?
95
- #
96
- def self.preview_lines
97
- return 7
98
- end
99
-
100
- # ---------------------------------------------------------------------
101
- # Private
102
- # ---------------------------------------------------------------------
103
-
104
- private
105
-
106
- #
107
- # Initialize gloo's root path.
108
- #
109
- def init_root
110
- if in_test_mode?
111
- path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
112
- path = File.dirname( File.dirname( path ) )
113
- path = File.join( path, 'test', 'gloo' )
114
- @user_root = path
115
- else
116
- @user_root = File.join( Dir.home, 'gloo' )
117
- end
118
- end
119
-
120
- #
121
- # Get the app's required directories.
122
- #
123
- def init_path_settings
124
- Dir.mkdir( @user_root ) unless File.exist?( @user_root )
125
-
126
- @log_path = File.join( @user_root, 'logs' )
127
- Dir.mkdir( @log_path ) unless File.exist?( @log_path )
128
-
129
- @config_path = File.join( @user_root, 'config' )
130
- Dir.mkdir( @config_path ) unless File.exist?( @config_path )
131
-
132
- @tmp_path = File.join( @user_root, 'tmp' )
133
- Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
134
-
135
- @debug_path = File.join( @user_root, 'debug' )
136
- Dir.mkdir( @debug_path ) unless File.exist?( @debug_path )
137
- end
138
-
139
- #
140
- # Initialize the user settings for the currently
141
- # running environment.
142
- #
143
- def init_user_settings
144
- settings = get_settings
145
-
146
- @project_path = project_path_for_mode settings
147
- @start_with = settings[ 'gloo' ][ 'start_with' ]
148
- @list_indent = settings[ 'gloo' ][ 'list_indent' ]
149
-
150
- @debug = settings[ 'gloo' ][ 'debug' ]
151
- end
152
-
153
- #
154
- # Get the app's required directories.
155
- #
156
- def get_settings
157
- f = File.join( @config_path, 'gloo.yml' )
158
- create_settings( f ) unless File.exist?( f )
159
- return YAML.load_file f
160
- end
161
-
162
- #
163
- # Create settings file.
164
- #
165
- def create_settings( file )
166
- IO.write( file, get_default_settings )
167
- end
168
-
169
- #
170
- # Get the value for default settings.
171
- #
172
- def get_default_settings
173
- projects = File.join( @user_root, 'projects' )
174
- str = <<~TEXT
175
- gloo:
176
- project_path: #{projects}
177
- start_with:
178
- list_indent: 1
179
- debug: false
180
- TEXT
181
- return str
182
- end
183
-
184
- end
185
- end
186
- end