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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa0507913bb322d98577252dce4f699185f09d2dc87dc4a8f80ea4fc71859fcc
4
- data.tar.gz: 7539b9d58d14baeb60cd98cdea9c92f3330d00da5e1c743fd81aefc7246d03e8
3
+ metadata.gz: 19496a960895aafa43d063747006006f73974b35932d46e2b6e16348f94ebd12
4
+ data.tar.gz: ea5df8220074a3d6d9b2e9316696287fe9176f22bcbbd6ca6f0ae3f1108cf983
5
5
  SHA512:
6
- metadata.gz: c1df92b449aeb3344d47fd8aa3d68b1b7e0ef9001444efbb66897038d8e189d435439c9844afa54948e19c2c161c31213e31ef5ea0573ea31429e30d2f718c51
7
- data.tar.gz: '028f3fe632304b2e947f9955e42d1aa0b768384c9649a112dc47e2d4c2d69e034f586c8b10f0c416dd09f506ec814f8a61f0ca6c7bb2e442e8d0e85846a98d94'
6
+ metadata.gz: 98f6ed2211824bbc5af791b32b1c2a55e5bc70dd91c6fe2440a2820324f2143c39860f89d458787dfba7405eb79f5dcd25f961b2cc9944350347e12d2daa60b6
7
+ data.tar.gz: ac15204c8c19dc59c87335da8d491436f540976bfba1d2304e38493ec07ba733005333e19f00a26753d4b83c30a86ef5e6764747663562a11787be68cb2c02b0
@@ -0,0 +1,73 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'gloo.gemspec'
4
+
5
+ # -------------- Layout -------------- #
6
+ Layout/SpaceInsideParens:
7
+ EnforcedStyle: space
8
+ Layout/EmptyLinesAroundClassBody:
9
+ EnforcedStyle: empty_lines
10
+ Layout/SpaceAroundMethodCallOperator:
11
+ Enabled: true
12
+ Layout/SpaceInsideArrayLiteralBrackets:
13
+ EnforcedStyle: space
14
+ Layout/SpaceInsideReferenceBrackets:
15
+ Enabled: true
16
+ EnforcedStyle: space
17
+
18
+ # -------------- Style -------------- #
19
+ Style/RescueStandardError:
20
+ EnforcedStyle: implicit
21
+ Style/HashSyntax:
22
+ EnforcedStyle: no_mixed_keys
23
+ Style/ExponentialNotation:
24
+ Enabled: true
25
+ Style/HashEachMethods:
26
+ Enabled: true
27
+ Style/HashTransformKeys:
28
+ Enabled: true
29
+ Style/HashTransformValues:
30
+ Enabled: true
31
+ Style/RedundantReturn:
32
+ Enabled: false
33
+ Style/FrozenStringLiteralComment:
34
+ Enabled: false
35
+ Style/GlobalVars:
36
+ Enabled: false
37
+ Style/Documentation:
38
+ Enabled: false
39
+ Style/RedundantSelf:
40
+ Enabled: false
41
+
42
+ # -------------- Naming -------------- #
43
+ Naming/PredicateName:
44
+ Enabled: true
45
+ Naming/AccessorMethodName:
46
+ Enabled: false
47
+
48
+ # -------------- Metrics -------------- #
49
+ Metrics/MethodLength:
50
+ Max: 17 # Default is 10
51
+ Enabled: true
52
+ Metrics/CyclomaticComplexity:
53
+ Max: 9 # Default is 6
54
+ Naming/MethodParameterName:
55
+ MinNameLength: 2 # Default value is 3
56
+ Metrics/PerceivedComplexity:
57
+ Max: 10 # default value is 7
58
+ Metrics/ClassLength:
59
+ Max: 137 # default is 100
60
+ Metrics/AbcSize:
61
+ Max: 37 # default is 15
62
+
63
+ # -------------- Lint -------------- #
64
+ Lint/RaiseException:
65
+ Enabled: true
66
+ Lint/StructNewOverride:
67
+ Enabled: true
68
+ Lint/NonDeterministicRequireOrder:
69
+ Enabled: false
70
+
71
+ # -------------- Security -------------- #
72
+ Security/Eval:
73
+ Enabled: true
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in gloo.gemspec
6
6
  gemspec
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gloo (0.3.0)
5
- activesupport (~> 5.2, >= 5.2.1)
4
+ gloo (0.4.0)
5
+ activesupport (~> 5.2, >= 5.2.4.3)
6
6
  chronic (~> 0.10, >= 0.10.2)
7
7
  colorize (~> 0.8, >= 0.8.1)
8
8
  tty (~> 0.8, >= 0.8.1)
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (5.2.2)
13
+ activesupport (5.2.4.3)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 0.7, < 2)
16
16
  minitest (~> 5.1)
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new(:test) do |t|
5
- ENV[ 'GLOO_ENV' ] = "TEST"
5
+ ENV[ 'GLOO_ENV' ] = 'TEST'
6
6
 
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
10
  end
11
11
 
12
12
  task :default => :test
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "gloo"
3
+ require 'bundler/setup'
4
+ require 'gloo'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -4,15 +4,15 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require "gloo/app/info"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "gloo"
7
+ spec.name = 'gloo'
8
8
  spec.version = Gloo::App::Info::VERSION
9
- spec.authors = ["Eric Crane"]
10
- spec.email = ["eric.crane@mac.com"]
9
+ spec.authors = ['Eric Crane']
10
+ spec.email = ['eric.crane@mac.com']
11
11
 
12
12
  spec.summary = %q{Gloo scripting language. A scripting language built on ruby.}
13
13
  spec.description = %q{A scripting languge to keep it all together.}
14
14
  spec.homepage = "http://github.com/ecrane/gloo"
15
- spec.license = "MIT"
15
+ spec.license = 'MIT'
16
16
 
17
17
  # Specify which files should be added to the gem when it is released.
18
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -20,19 +20,20 @@ Gem::Specification.new do |spec|
20
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
21
  end
22
22
 
23
- spec.bindir = "exe"
23
+ spec.bindir = 'exe'
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
- spec.require_paths = ["lib"]
26
-
27
- spec.executables << "o"
28
- spec.executables << "gloo"
29
-
30
- spec.add_development_dependency "bundler", "~> 1.16"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "minitest", "~> 5.0"
33
-
34
- spec.add_dependency "activesupport", "~> 5.2", '>= 5.2.1'
35
- spec.add_dependency "chronic", "~> 0.10", '>= 0.10.2'
36
- spec.add_dependency "tty", "~> 0.8", '>= 0.8.1'
37
- spec.add_dependency "colorize", "~> 0.8", '>= 0.8.1'
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.executables << 'o'
28
+ spec.executables << 'gloo'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.16'
31
+ spec.add_development_dependency 'minitest', '~> 5.0'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+
34
+ spec.add_dependency "activesupport", '~> 5.2', ">= 5.2.4.3"
35
+ # spec.add_dependency 'activesupport', '~> 5.2', '>= 5.2.1'
36
+ spec.add_dependency 'chronic', '~> 0.10', '>= 0.10.2'
37
+ spec.add_dependency 'colorize', '~> 0.8', '>= 0.8.1'
38
+ spec.add_dependency 'tty', '~> 0.8', '>= 0.8.1'
38
39
  end
@@ -5,15 +5,15 @@
5
5
  #
6
6
 
7
7
  path = File.dirname( File.absolute_path( __FILE__ ) )
8
- root = File.join( path, "gloo", "**/*.rb" )
9
- Dir.glob( root ) { |ruby_file| require ruby_file }
10
-
11
- module Gloo
8
+ root = File.join( path, 'gloo', '**/*.rb' )
9
+ Dir.glob( root ).each do |ruby_file|
10
+ require ruby_file
11
+ end
12
12
 
13
+ module Gloo
13
14
  def self.run
14
15
  params = []
15
- ( params << "--cli" ) if ARGV.count == 0
16
+ ( params << '--cli' ) if ARGV.count.zero?
16
17
  Gloo::App::Engine.new( params ).start
17
18
  end
18
-
19
19
  end
@@ -11,61 +11,60 @@ require 'colorize'
11
11
  module Gloo
12
12
  module App
13
13
  class Args
14
-
15
- attr_reader :switches, :files
16
-
14
+
15
+ attr_reader :switches, :files
16
+
17
17
  def initialize( params = [] )
18
18
  @switches = []
19
19
  @files = []
20
-
20
+
21
21
  params.each { |o| process_one_arg( o ) }
22
22
  ARGV.each { |o| process_one_arg( o ) }
23
23
  end
24
-
24
+
25
25
  # Was the --quiet arg passed?
26
26
  def quiet?
27
- return @switches.include?( "quiet" )
27
+ return @switches.include?( 'quiet' )
28
28
  end
29
-
30
- #
29
+
30
+ #
31
31
  # Detect the mode to be run in.
32
32
  # Start by seeing if a mode is specified.
33
33
  # Then look for the presence of files.
34
34
  # Then finally use the default: embedded mode.
35
- #
35
+ #
36
36
  def detect_mode
37
- if ENV[ 'GLOO_ENV' ] == "test"
38
- mode = Mode::TEST
39
- elsif @switches.include?( "version" )
40
- mode = Mode::VERSION
41
- elsif @switches.include?( "help" )
42
- mode = Mode::HELP
43
- elsif @switches.include?( "cli" )
44
- mode = Mode::CLI
45
- elsif @switches.include?( "embed" )
46
- mode = Mode::EMBED
47
- elsif @files.count > 0
48
- mode = Mode::SCRIPT
49
- else
50
- mode = Mode.default_mode
51
- end
37
+ mode = if ENV[ 'GLOO_ENV' ] == 'test'
38
+ Mode::TEST
39
+ elsif @switches.include?( 'version' )
40
+ Mode::VERSION
41
+ elsif @switches.include?( 'help' )
42
+ Mode::HELP
43
+ elsif @switches.include?( 'cli' )
44
+ Mode::CLI
45
+ elsif @switches.include?( 'embed' )
46
+ Mode::EMBED
47
+ elsif @files.count.positive?
48
+ Mode::SCRIPT
49
+ else
50
+ Mode.default_mode
51
+ end
52
52
  $log.debug "running in #{mode} mode"
53
-
53
+
54
54
  return mode
55
55
  end
56
56
 
57
-
58
57
  private
59
-
58
+
60
59
  # Process one argument or parameter.
61
- def process_one_arg arg
62
- if arg.start_with? "--"
63
- switches << arg[2..-1]
60
+ def process_one_arg( arg )
61
+ if arg.start_with? '--'
62
+ switches << arg[ 2..-1 ]
64
63
  else
65
64
  files << arg
66
65
  end
67
66
  end
68
-
67
+
69
68
  end
70
69
  end
71
70
  end
@@ -15,24 +15,24 @@ module Gloo
15
15
  attr_reader :args, :mode, :running
16
16
  attr_reader :dictionary, :parser, :heap, :factory
17
17
  attr_accessor :last_cmd, :persist_man, :event_manager
18
-
18
+
19
19
  # Set up the engine with basic elements.
20
20
  def initialize( params = [] )
21
21
  $engine = self
22
22
  @args = Args.new( params )
23
23
  $settings = Settings.new( ENV[ 'GLOO_ENV' ] )
24
24
  $log = Log.new( @args.quiet? )
25
- $prompt = TTY::Prompt.new
26
- $log.debug "engine intialized..."
25
+ $prompt = TTY::Prompt.new
26
+ $log.debug 'engine intialized...'
27
27
  end
28
-
28
+
29
29
  # Start the engine.
30
30
  def start
31
- $log.debug "starting the engine..."
31
+ $log.debug 'starting the engine...'
32
32
  $log.debug Info.display_title
33
33
  @mode = @args.detect_mode
34
34
  @running = true
35
-
35
+
36
36
  @dictionary = Gloo::Core::Dictionary.instance
37
37
  @dictionary.init
38
38
  @parser = Gloo::Core::Parser.new
@@ -40,10 +40,10 @@ module Gloo
40
40
  @factory = Gloo::Core::Factory.new
41
41
  @persist_man = Gloo::Persist::PersistMan.new
42
42
  @event_manager = Gloo::Core::EventManager.new
43
-
43
+
44
44
  run_mode
45
45
  end
46
-
46
+
47
47
  # Run the selected mode.
48
48
  def run_mode
49
49
  if @mode == Mode::VERSION
@@ -56,14 +56,14 @@ module Gloo
56
56
  run
57
57
  end
58
58
  end
59
-
59
+
60
60
  # Run files specified on the CLI.
61
61
  # Then quit.
62
62
  def run_files
63
63
  @args.files.each do |f|
64
64
  @persist_man.load( f )
65
65
  end
66
-
66
+
67
67
  quit
68
68
  end
69
69
 
@@ -71,17 +71,17 @@ module Gloo
71
71
  def run
72
72
  # Open default files
73
73
  self.open_start_file
74
-
74
+
75
75
  # TODO: open any files specifed in args
76
-
76
+
77
77
  unless @mode == Mode::SCRIPT || @args.quiet?
78
78
  @cursor = TTY::Cursor
79
- self.loop
79
+ self.loop
80
80
  end
81
81
 
82
82
  quit
83
83
  end
84
-
84
+
85
85
  # Get the setting for the start_with file and open it.
86
86
  def open_start_file
87
87
  name = $settings.start_with
@@ -96,7 +96,7 @@ module Gloo
96
96
 
97
97
  @last_cmd = $prompt.ask( "#{d.yellow} #{t.white} >" )
98
98
  end
99
-
99
+
100
100
  # Is the last command entered blank?
101
101
  def last_cmd_blank?
102
102
  return true if @last_cmd.nil?
@@ -110,28 +110,28 @@ module Gloo
110
110
  process_cmd
111
111
  end
112
112
  end
113
-
113
+
114
114
  # Process the command.
115
115
  def process_cmd
116
116
  if last_cmd_blank?
117
117
  clear_screen
118
118
  return
119
119
  end
120
-
120
+
121
121
  @immediate = @parser.parse_immediate @last_cmd
122
- @immediate.run if @immediate
122
+ Gloo::Core::Runner.go( @immediate ) if @immediate
123
123
  end
124
124
 
125
125
  # Request the engine to stop running.
126
126
  def stop_running
127
127
  @running = false
128
128
  end
129
-
129
+
130
130
  # Do any clean up and quit.
131
131
  def quit
132
- $log.debug "quitting..."
132
+ $log.debug 'quitting...'
133
133
  end
134
-
134
+
135
135
  # Show the version information and then quit.
136
136
  def run_version
137
137
  puts Info.display_title unless @args.quiet?
@@ -139,20 +139,25 @@ module Gloo
139
139
  end
140
140
 
141
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
142
+ def run_help( keep_running = false )
143
+ out = "#{Info.display_title}\n"
144
+ out << Help.get_help_text
145
+ $engine.heap.it.set_to out
146
+ puts out unless @args.quiet?
147
147
  quit unless keep_running
148
148
  end
149
-
149
+
150
150
  # Clear the screen.
151
151
  def clear_screen
152
152
  print @cursor.clear_screen
153
153
  print @cursor.move_to( 0, 0 )
154
154
  end
155
-
155
+
156
+ # Did the last command result in an error?
157
+ def error?
158
+ return !@heap.error.value.nil?
159
+ end
160
+
156
161
  end
157
162
  end
158
163
  end