geordi 2.12.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +8 -2
  4. data/CHANGELOG.md +8 -0
  5. data/Gemfile +2 -6
  6. data/Gemfile.lock +20 -25
  7. data/README.md +8 -28
  8. data/Rakefile +6 -10
  9. data/{bin → exe}/b +0 -0
  10. data/{bin → exe}/cap-all +0 -0
  11. data/{bin → exe}/console-for +0 -0
  12. data/{bin → exe}/cuc +0 -0
  13. data/{bin → exe}/cuc-show +0 -0
  14. data/{bin → exe}/cuc-vnc-setup +0 -0
  15. data/{bin → exe}/deploy-to-production +0 -0
  16. data/{bin → exe}/dump-for +0 -0
  17. data/{bin → exe}/dumple +0 -0
  18. data/{bin → exe}/geordi +0 -2
  19. data/{bin → exe}/gitpt +0 -0
  20. data/{bin → exe}/launchy_browser +0 -0
  21. data/{bin → exe}/load-dump +0 -0
  22. data/{bin → exe}/migrate-all +0 -0
  23. data/{bin → exe}/rs +0 -0
  24. data/{bin → exe}/run_tests +0 -0
  25. data/{bin → exe}/shell-for +0 -0
  26. data/{bin → exe}/tests +0 -0
  27. data/geordi.gemspec +23 -20
  28. data/lib/geordi/COMMAND_TEMPLATE +2 -3
  29. data/lib/geordi/capistrano_config.rb +7 -7
  30. data/lib/geordi/chromedriver_updater.rb +7 -7
  31. data/lib/geordi/cli.rb +1 -6
  32. data/lib/geordi/commands/_setup_vnc.rb +1 -1
  33. data/lib/geordi/commands/apache_site.rb +3 -3
  34. data/lib/geordi/commands/bundle_install.rb +2 -2
  35. data/lib/geordi/commands/capistrano.rb +2 -3
  36. data/lib/geordi/commands/chromedriver_update.rb +0 -9
  37. data/lib/geordi/commands/clean.rb +2 -4
  38. data/lib/geordi/commands/commit.rb +0 -1
  39. data/lib/geordi/commands/console.rb +2 -2
  40. data/lib/geordi/commands/create_database_yml.rb +2 -2
  41. data/lib/geordi/commands/create_databases.rb +2 -2
  42. data/lib/geordi/commands/cucumber.rb +20 -20
  43. data/lib/geordi/commands/delete_dumps.rb +9 -9
  44. data/lib/geordi/commands/deploy.rb +12 -13
  45. data/lib/geordi/commands/drop_databases.rb +12 -14
  46. data/lib/geordi/commands/dump.rb +5 -6
  47. data/lib/geordi/commands/eurest.rb +2 -2
  48. data/lib/geordi/commands/firefox.rb +3 -3
  49. data/lib/geordi/commands/png_optimize.rb +13 -12
  50. data/lib/geordi/commands/rake.rb +2 -2
  51. data/lib/geordi/commands/remove_executable_flags.rb +1 -1
  52. data/lib/geordi/commands/rspec.rb +6 -6
  53. data/lib/geordi/commands/security_update.rb +12 -12
  54. data/lib/geordi/commands/server.rb +5 -5
  55. data/lib/geordi/commands/setup.rb +5 -5
  56. data/lib/geordi/commands/shell.rb +2 -2
  57. data/lib/geordi/commands/unit.rb +1 -1
  58. data/lib/geordi/commands/update.rb +5 -5
  59. data/lib/geordi/commands/vnc.rb +1 -1
  60. data/lib/geordi/commands/with_rake.rb +1 -1
  61. data/lib/geordi/commands/yarn_install.rb +2 -2
  62. data/lib/geordi/cucumber.rb +28 -29
  63. data/lib/geordi/db_cleaner.rb +28 -28
  64. data/lib/geordi/dump_loader.rb +3 -3
  65. data/lib/geordi/firefox_for_selenium.rb +11 -12
  66. data/lib/geordi/gitpt.rb +13 -13
  67. data/lib/geordi/remote.rb +6 -6
  68. data/lib/geordi/util.rb +18 -24
  69. data/lib/geordi/version.rb +1 -1
  70. metadata +25 -42
  71. data/features/commit.feature +0 -17
  72. data/features/console.feature +0 -7
  73. data/features/cucumber.feature +0 -261
  74. data/features/deploy.feature +0 -66
  75. data/features/docker.feature +0 -86
  76. data/features/dump.feature +0 -34
  77. data/features/firefox.feature +0 -44
  78. data/features/server.feature +0 -31
  79. data/features/setup.feature +0 -11
  80. data/features/shell.feature +0 -78
  81. data/features/step_definitions/docker_command_steps.rb +0 -21
  82. data/features/step_definitions/miscellaneous_steps.rb +0 -11
  83. data/features/support/aruba.rb +0 -60
  84. data/features/support/env.rb +0 -9
  85. data/features/support/step_definitions/aruba_backport_steps.rb +0 -5
  86. data/lib/geordi/commands/docker.rb +0 -42
  87. data/lib/geordi/docker.rb +0 -116
@@ -11,10 +11,10 @@ module Geordi
11
11
  puts "We're going to run `sudo -u postgres psql` for PostgreSQL"
12
12
  puts ' and `sudo mysql` for MariaDB (which uses PAM auth)'
13
13
  `sudo true`
14
- fail 'sudo access is required for database operations as database users' if $? != 0
14
+ raise 'sudo access is required for database operations as database users' if $CHILD_STATUS != 0
15
15
  @derivative_dbname = /_(test\d*|development|cucumber)$/
16
16
  base_directory = ENV['XDG_CONFIG_HOME']
17
- base_directory = "#{Dir.home}" if base_directory.nil?
17
+ base_directory = Dir.home.to_s if base_directory.nil?
18
18
  @whitelist_directory = File.join(base_directory, '.config', 'geordi', 'whitelists')
19
19
  FileUtils.mkdir_p(@whitelist_directory) unless File.directory? @whitelist_directory
20
20
  @mysql_command = decide_mysql_command(extra_flags['mysql'])
@@ -23,11 +23,11 @@ module Geordi
23
23
 
24
24
  def edit_whitelist(dbtype)
25
25
  whitelist = whitelist_fname(dbtype)
26
- if File.exist? whitelist
27
- whitelisted_dbs = Geordi::Util.stripped_lines(File.read(whitelist))\
26
+ whitelisted_dbs = if File.exist? whitelist
27
+ Geordi::Util.stripped_lines(File.read(whitelist))\
28
28
  .delete_if { |l| l.start_with? '#' }
29
29
  else
30
- whitelisted_dbs = Array.new
30
+ []
31
31
  end
32
32
  all_dbs = list_all_dbs(dbtype)
33
33
  tmp = Tempfile.open("geordi_whitelist_#{dbtype}")
@@ -82,16 +82,16 @@ HEREDOC
82
82
  texteditor = Geordi::Util.decide_texteditor
83
83
  system("#{texteditor} #{tmp.path}")
84
84
  File.open(tmp.path, 'r') do |wl_edited|
85
- whitelisted_dbs = Array.new
85
+ whitelisted_dbs = []
86
86
  whitelist_storage = File.open(whitelist, 'w')
87
87
  lines = Geordi::Util.stripped_lines(wl_edited.read)
88
88
  lines.each do |line|
89
89
  next if line.start_with?('#')
90
90
  unless line.split.length == 2
91
- fail "Invalid edit to whitelist file: \`#{line}\` - Syntax is: ^[keep|drop] dbname$"
91
+ raise "Invalid edit to whitelist file: \`#{line}\` - Syntax is: ^[keep|drop] dbname$"
92
92
  end
93
93
  unless %w[keep drop k d].include? line.split.first
94
- fail "Invalid edit to whitelist file: \`#{line}\` - must start with either drop or keep."
94
+ raise "Invalid edit to whitelist file: \`#{line}\` - must start with either drop or keep."
95
95
  end
96
96
  db_status, db_name = line.split
97
97
  if db_status == 'keep'
@@ -107,32 +107,32 @@ HEREDOC
107
107
  cmd = 'sudo mysql'
108
108
  unless extra_flags.nil?
109
109
  if extra_flags.include? 'port'
110
- port = Integer(extra_flags.split('=')[1].split()[0])
111
- fail "Port #{port} is not open" unless Geordi::Util.is_port_open? port
110
+ port = Integer(extra_flags.split('=')[1].split[0])
111
+ raise "Port #{port} is not open" unless Geordi::Util.is_port_open? port
112
112
  end
113
113
  cmd << " #{extra_flags}"
114
114
  end
115
- Open3.popen3("#{cmd} -e 'QUIT'") do |stdin, stdout, stderr, thread|
115
+ Open3.popen3("#{cmd} -e 'QUIT'") do |_stdin, _stdout, stderr, thread|
116
116
  break if thread.value.exitstatus == 0
117
117
  # sudo mysql was not successful, switching to mysql-internal user management
118
118
  mysql_error = stderr.read.lines[0].chomp.strip.split[1]
119
- if %w[1045 1698].include? mysql_error # authentication failed
119
+ if %w[1045 1698].include? mysql_error # authentication failed
120
120
  cmd = 'mysql -uroot'
121
121
  cmd << " #{extra_flags}" unless extra_flags.nil?
122
122
  unless File.exist? File.join(Dir.home, '.my.cnf')
123
123
  puts "Please enter your MySQL/MariaDB password for account 'root'."
124
124
  warn "You should create a ~/.my.cnf file instead, or you'll need to enter your MySQL root password for each db."
125
- warn "See https://makandracards.com/makandra/50813-store-mysql-passwords-for-development for more information."
126
- cmd << ' -p' # need to ask for password now
125
+ warn 'See https://makandracards.com/makandra/50813-store-mysql-passwords-for-development for more information.'
126
+ cmd << ' -p' # need to ask for password now
127
127
  end
128
- Open3.popen3("#{cmd} -e 'QUIT'") do |stdin2, stdout2, stderr2, thread2|
129
- fail 'Could not connect to MySQL/MariaDB' unless thread2.value.exitstatus == 0
128
+ Open3.popen3("#{cmd} -e 'QUIT'") do |_stdin_2, _stdout_2, _stderr_2, thread_2|
129
+ raise 'Could not connect to MySQL/MariaDB' unless thread_2.value.exitstatus == 0
130
130
  end
131
- elsif mysql_error == '2013' # connection to port or socket failed
132
- fail 'MySQL/MariaDB connection failed, is this the correct port?'
131
+ elsif mysql_error == '2013' # connection to port or socket failed
132
+ raise 'MySQL/MariaDB connection failed, is this the correct port?'
133
133
  end
134
134
  end
135
- return cmd
135
+ cmd
136
136
  end
137
137
  private :decide_mysql_command
138
138
 
@@ -141,22 +141,22 @@ HEREDOC
141
141
  unless extra_flags.nil?
142
142
  begin
143
143
  port = Integer(extra_flags.split('=')[1])
144
- fail "Port #{port} is not open" unless Geordi::Util.is_port_open? port
144
+ raise "Port #{port} is not open" unless Geordi::Util.is_port_open? port
145
145
  rescue ArgumentError
146
146
  socket = extra_flags.split('=')[1]
147
- fail "Socket #{socket} does not exist" unless File.exist? socket
147
+ raise "Socket #{socket} does not exist" unless File.exist? socket
148
148
  end
149
149
  cmd << " #{extra_flags}"
150
150
  end
151
- return cmd
151
+ cmd
152
152
  end
153
153
  private :decide_postgres_command
154
154
 
155
155
  def list_all_dbs(dbtype)
156
156
  if dbtype == 'postgres'
157
- return list_all_postgres_dbs
157
+ list_all_postgres_dbs
158
158
  else
159
- return list_all_mysql_dbs
159
+ list_all_mysql_dbs
160
160
  end
161
161
  end
162
162
 
@@ -224,7 +224,7 @@ HEREDOC
224
224
  end
225
225
  case proceed
226
226
  when 'e'
227
- proceed = '' # reset user selection
227
+ proceed = '' # reset user selection
228
228
  edit_whitelist dbtype
229
229
  when 'n'
230
230
  success 'Not deleting anything'
@@ -245,10 +245,10 @@ HEREDOC
245
245
  end
246
246
 
247
247
  def is_whitelisted?(dbtype, database_name)
248
- if File.exist? whitelist_fname(dbtype)
249
- whitelist_content = Geordi::Util.stripped_lines(File.open(whitelist_fname(dbtype), 'r').read)
248
+ whitelist_content = if File.exist? whitelist_fname(dbtype)
249
+ Geordi::Util.stripped_lines(File.open(whitelist_fname(dbtype), 'r').read)
250
250
  else
251
- whitelist_content = Array.new
251
+ []
252
252
  end
253
253
  # Allow explicit whitelisting of derivative databases like projectname_test2
254
254
  if whitelist_content.include? database_name
@@ -14,7 +14,7 @@ module Geordi
14
14
  def development_database_config
15
15
  require 'yaml'
16
16
 
17
- @config ||= YAML::load(ERB.new(File.read('config/database.yml')).result)
17
+ @config ||= YAML.safe_load(ERB.new(File.read('config/database.yml')).result)
18
18
  @config['development']
19
19
  end
20
20
  alias_method :config, :development_database_config
@@ -47,7 +47,7 @@ module Geordi
47
47
  available_dumps = Dir.glob(dumps_glob).sort
48
48
 
49
49
  HighLine.new.choose(*available_dumps) do |menu|
50
- menu.hidden('') { fail 'Abort.' }
50
+ menu.hidden('') { raise 'Abort.' }
51
51
  end
52
52
  end
53
53
  end
@@ -56,7 +56,7 @@ module Geordi
56
56
  note 'Source file: ' + dump_file
57
57
 
58
58
  source_command = send("#{config['adapter']}_command")
59
- Util.system! source_command, :fail_message => "An error occured loading #{File.basename(dump_file)}"
59
+ Util.system! source_command, fail_message: "An error occured loading #{File.basename(dump_file)}"
60
60
  end
61
61
 
62
62
  end
@@ -1,13 +1,13 @@
1
1
  require 'pathname'
2
2
  require 'tempfile'
3
- require File.expand_path('../interaction', __FILE__)
3
+ require File.expand_path('interaction', __dir__)
4
4
 
5
5
  module Geordi
6
6
  module FirefoxForSelenium
7
7
  extend Geordi::Interaction
8
8
 
9
9
  FIREFOX_FOR_SELENIUM_BASE_PATH = Pathname.new('~/bin/firefoxes').expand_path
10
- FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'
10
+ FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'.freeze
11
11
  FIREFOX_VERSION_FILE = Pathname.new('.firefox-version')
12
12
 
13
13
  def self.install(version)
@@ -17,16 +17,16 @@ module Geordi
17
17
  def self.path_from_config
18
18
  version = FIREFOX_VERSION_FILE.exist? && File.read(FIREFOX_VERSION_FILE).strip
19
19
 
20
- if version and version != 'system'
20
+ if version && (version != 'system')
21
21
  unless FirefoxForSelenium.binary(version).exist?
22
- warn "Firefox #{ version } not found"
22
+ warn "Firefox #{version} not found"
23
23
 
24
24
  note strip_heredoc(<<-INSTRUCTIONS)
25
25
  Install it with
26
- geordi firefox --setup #{ version }
26
+ geordi firefox --setup #{version}
27
27
  INSTRUCTIONS
28
28
 
29
- prompt 'Run tests anyway?', 'n', /y|yes/ or fail 'Cancelled.'
29
+ prompt('Run tests anyway?', 'n', /y|yes/) || raise('Cancelled.')
30
30
  end
31
31
 
32
32
  path(version)
@@ -37,7 +37,7 @@ module Geordi
37
37
  FIREFOX_FOR_SELENIUM_BASE_PATH.join(version)
38
38
  end
39
39
 
40
- def self.binary(version, name = "firefox")
40
+ def self.binary(version, name = 'firefox')
41
41
  path(version).join(name)
42
42
  end
43
43
 
@@ -72,7 +72,7 @@ module Geordi
72
72
  private
73
73
 
74
74
  def execute_command(cmd)
75
- system(cmd) or raise "Error while executing command: #{cmd}"
75
+ system(cmd) || raise("Error while executing command: #{cmd}")
76
76
  end
77
77
 
78
78
  def run_firefox_for_selenium(args = '')
@@ -92,7 +92,7 @@ module Geordi
92
92
  end
93
93
 
94
94
  def original_binary
95
- FirefoxForSelenium.binary(@version, "firefox-original")
95
+ FirefoxForSelenium.binary(@version, 'firefox-original')
96
96
  end
97
97
 
98
98
  def say_hello
@@ -137,7 +137,7 @@ module Geordi
137
137
  INSTRUCTION
138
138
  prompt 'Continue?'
139
139
 
140
- File.file?(binary) or raise "Could not find #{binary}"
140
+ File.file?(binary) || raise("Could not find #{binary}")
141
141
  end
142
142
 
143
143
  def create_separate_profile
@@ -156,7 +156,7 @@ module Geordi
156
156
  patched_binary.write strip_heredoc(<<-PATCH)
157
157
  #!/usr/bin/env ruby
158
158
  exec('#{original_binary}', '-no-remote', '-P', '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}', *ARGV)
159
- PATCH
159
+ PATCH
160
160
  patched_binary.close
161
161
  execute_command("mv #{patched_binary.path} #{binary}")
162
162
  execute_command("chmod +x #{binary}")
@@ -200,4 +200,3 @@ module Geordi
200
200
  end
201
201
  end
202
202
  end
203
-
data/lib/geordi/gitpt.rb CHANGED
@@ -4,8 +4,8 @@ class Gitpt
4
4
  require 'highline'
5
5
  require 'tracker_api'
6
6
 
7
- SETTINGS_FILE_NAME = '.gitpt'
8
- PROJECT_IDS_FILE_NAME = '.pt_project_id'
7
+ SETTINGS_FILE_NAME = '.gitpt'.freeze
8
+ PROJECT_IDS_FILE_NAME = '.pt_project_id'.freeze
9
9
 
10
10
  def initialize
11
11
  self.highline = HighLine.new
@@ -13,7 +13,7 @@ class Gitpt
13
13
  end
14
14
 
15
15
  def run(git_args)
16
- warn <<-WARNING if !Geordi::Util.staged_changes?
16
+ warn <<-WARNING unless Geordi::Util.staged_changes?
17
17
  No staged changes. Will create an empty commit.
18
18
  WARNING
19
19
 
@@ -30,16 +30,16 @@ No staged changes. Will create an empty commit.
30
30
  def read_settings
31
31
  file_path = File.join(ENV['HOME'], SETTINGS_FILE_NAME)
32
32
 
33
- unless File.exists?(file_path)
33
+ unless File.exist?(file_path)
34
34
  highline.say HighLine::RESET
35
35
  highline.say "Welcome to #{bold 'gitpt'}.\n\n"
36
36
 
37
37
  highline.say highlight('Your settings are missing or invalid.')
38
38
  highline.say "Please configure your Pivotal Tracker access.\n\n"
39
- token = highline.ask bold("Your API key:") + " "
39
+ token = highline.ask bold('Your API key:') + ' '
40
40
  highline.say "\n"
41
41
 
42
- settings = { :token => token }
42
+ settings = { token: token }
43
43
  File.open(file_path, 'w') do |file|
44
44
  file.write settings.to_yaml
45
45
  end
@@ -49,7 +49,7 @@ No staged changes. Will create an empty commit.
49
49
  end
50
50
 
51
51
  def build_client(settings)
52
- TrackerApi::Client.new(:token => settings.fetch(:token))
52
+ TrackerApi::Client.new(token: settings.fetch(:token))
53
53
  end
54
54
 
55
55
  def load_projects
@@ -60,11 +60,11 @@ No staged changes. Will create an empty commit.
60
60
  def read_project_ids
61
61
  file_path = PROJECT_IDS_FILE_NAME
62
62
 
63
- if File.exists?(file_path)
63
+ if File.exist?(file_path)
64
64
  project_ids = File.read('.pt_project_id').split(/[\s]+/).map(&:to_i)
65
65
  end
66
66
 
67
- if project_ids and project_ids.size > 0
67
+ if project_ids && (project_ids.size > 0)
68
68
  project_ids
69
69
  else
70
70
  warn "Sorry, I could not find a project ID in #{file_path} :("
@@ -79,19 +79,19 @@ No staged changes. Will create an empty commit.
79
79
  def applicable_stories
80
80
  projects = load_projects
81
81
  projects.collect do |project|
82
- project.stories(:filter => 'state:started,finished,rejected')
82
+ project.stories(filter: 'state:started,finished,rejected')
83
83
  end.flatten
84
84
  end
85
85
 
86
86
  def choose_story
87
87
  if Geordi::Util.testing?
88
- return OpenStruct.new(:id => 12, :name => 'Test Story')
88
+ return OpenStruct.new(id: 12, name: 'Test Story')
89
89
  end
90
90
 
91
91
  loading_message = 'Connecting to Pivotal Tracker ...'
92
92
  print(loading_message)
93
93
  stories = applicable_stories
94
- reset_loading_message = "\r#{ ' ' * (loading_message.length + stories.length)}\r"
94
+ reset_loading_message = "\r#{' ' * (loading_message.length + stories.length)}\r"
95
95
 
96
96
  highline.choose do |menu|
97
97
  menu.header = 'Choose a story'
@@ -126,7 +126,7 @@ No staged changes. Will create an empty commit.
126
126
 
127
127
  def create_commit(message, *git_args)
128
128
  extra = highline.ask("\nAdd an optional message").strip
129
- message << ' - ' << extra if (extra != "")
129
+ message << ' - ' << extra if extra != ''
130
130
 
131
131
  Geordi::Util.system! 'git', 'commit', '--allow-empty', '-m', message, *git_args
132
132
  end
data/lib/geordi/remote.rb CHANGED
@@ -8,7 +8,7 @@ module Geordi
8
8
  class Remote
9
9
  include Geordi::Interaction
10
10
 
11
- REMOTE_DUMP_PATH = '~/dumps/dump_for_download.dump'
11
+ REMOTE_DUMP_PATH = '~/dumps/dump_for_download.dump'.freeze
12
12
 
13
13
  def initialize(stage)
14
14
  @stage = stage
@@ -34,8 +34,8 @@ module Geordi
34
34
  def dump(options = {})
35
35
  # Generate dump on the server
36
36
  shell options.merge({
37
- :remote_command => "dumple #{@config.env} --for_download",
38
- :select_server => nil # Dump must be generated on the primary server
37
+ remote_command: "dumple #{@config.env} --for_download",
38
+ select_server: nil, # Dump must be generated on the primary server
39
39
  })
40
40
 
41
41
  destination_directory = File.join(@config.root, 'tmp')
@@ -45,7 +45,7 @@ module Geordi
45
45
 
46
46
  note "Downloading remote dump to #{relative_destination} ..."
47
47
  server = @config.primary_server
48
- Util.system! "scp -C #{ @config.user(server) }@#{ server }:#{REMOTE_DUMP_PATH} #{destination_path}"
48
+ Util.system! "scp -C #{@config.user(server)}@#{server}:#{REMOTE_DUMP_PATH} #{destination_path}"
49
49
 
50
50
  success "Dumped the #{@stage} database to #{relative_destination}."
51
51
 
@@ -53,7 +53,7 @@ module Geordi
53
53
  end
54
54
 
55
55
  def console(options = {})
56
- shell(options.merge :remote_command => Util.console_command(@config.env))
56
+ shell(options.merge(remote_command: Util.console_command(@config.env)))
57
57
  end
58
58
 
59
59
  def shell(options = {})
@@ -63,7 +63,7 @@ module Geordi
63
63
  remote_command << " -c '#{options[:remote_command]}'" if options[:remote_command]
64
64
 
65
65
  note 'Connecting to ' + server.to_s
66
- Util.system! 'ssh', "#{ @config.user(server) }@#{ server }", '-t', remote_command
66
+ Util.system! 'ssh', "#{@config.user(server)}@#{server}", '-t', remote_command
67
67
  end
68
68
 
69
69
  end
data/lib/geordi/util.rb CHANGED
@@ -10,19 +10,19 @@ module Geordi
10
10
  # all employed gems as runtime dependencies because that would
11
11
  # unnecessarily slow down all commands.
12
12
  # Thus, we have this handy method here.
13
- def installing_missing_gems(&block)
13
+ def installing_missing_gems
14
14
  yield
15
15
  rescue LoadError => error
16
16
  error.message =~ /-- (\S+)\Z/
17
- $1 or raise # could not extract a gem name from the error message, re-raise the error
17
+ Regexp.last_match(1) || raise # could not extract a gem name from the error message, re-raise the error
18
18
 
19
- gem_name = $1.strip.split('/').first
19
+ gem_name = Regexp.last_match(1).strip.split('/').first
20
20
  install_command = 'gem install ' + gem_name
21
21
 
22
22
  # install missing gem
23
23
  warn 'Probably missing gem: ' + gem_name
24
- prompt('Install it now?', 'y', /y|yes/) or fail 'Missing Gems.'
25
- system! install_command, :show_cmd => true
24
+ prompt('Install it now?', 'y', /y|yes/) || raise('Missing Gems.')
25
+ system! install_command, show_cmd: true
26
26
 
27
27
  # retry
28
28
  Gem.clear_paths
@@ -42,16 +42,16 @@ module Geordi
42
42
  note_cmd commands.join(' ') if options[:show_cmd]
43
43
 
44
44
  if options[:confirm]
45
- prompt('Run this now?', 'n', /y|yes/) or fail('Cancelled.')
45
+ prompt('Run this now?', 'n', /y|yes/) || raise('Cancelled.')
46
46
  end
47
47
 
48
48
  if testing?
49
- puts "Util.system! #{ commands.join ', ' }"
49
+ puts "Util.system! #{commands.join ', '}"
50
50
  else
51
51
  # Remove Geordi's Bundler environment when running commands.
52
52
  success = if !defined?(Bundler)
53
53
  system(*commands)
54
- elsif Gem::Version.new(Bundler::VERSION) >= Gem::Version.new('1.17.3')
54
+ elsif Gem::Version.new(Bundler::VERSION) >= Gem::Version.new('2.1.2')
55
55
  Bundler.with_original_env do
56
56
  system(*commands)
57
57
  end
@@ -59,7 +59,7 @@ module Geordi
59
59
  Bundler.clean_system(*commands)
60
60
  end
61
61
 
62
- success or fail(options[:fail_message] || 'Something went wrong.')
62
+ success || raise(options[:fail_message] || 'Something went wrong.')
63
63
  end
64
64
  end
65
65
 
@@ -107,7 +107,7 @@ module Geordi
107
107
  # try to guess user's favorite cli text editor
108
108
  def decide_texteditor
109
109
  %w[/usr/bin/editor vi].each do |texteditor|
110
- if cmd_exists? texteditor and texteditor.start_with? '$'
110
+ if cmd_exists?(texteditor) && texteditor.start_with?('$')
111
111
  return ENV[texteditor[1..-1]]
112
112
  elsif cmd_exists? texteditor
113
113
  return texteditor
@@ -116,19 +116,17 @@ module Geordi
116
116
  end
117
117
 
118
118
  # check if given cmd is executable. Absolute path or command in $PATH allowed.
119
- def cmd_exists? cmd
119
+ def cmd_exists?(cmd)
120
120
  system("which #{cmd} > /dev/null")
121
- return $?.exitstatus.zero?
121
+ $CHILD_STATUS.exitstatus.zero?
122
122
  end
123
123
 
124
124
  def is_port_open?(port)
125
- begin
126
- socket = TCPSocket.new('127.0.0.1', port)
127
- socket.close
128
- return true
129
- rescue Errno::ECONNREFUSED
130
- return false
131
- end
125
+ socket = TCPSocket.new('127.0.0.1', port)
126
+ socket.close
127
+ true
128
+ rescue Errno::ECONNREFUSED
129
+ false
132
130
  end
133
131
 
134
132
  # splint lines e.g. read from a file into lines and clean those up
@@ -161,12 +159,8 @@ module Geordi
161
159
  nil
162
160
  end
163
161
 
164
- def ruby_version
165
- Gem::Version.new(RUBY_VERSION)
166
- end
167
-
168
162
  def file_containing?(file, regex)
169
- File.exists?(file) and File.read(file).scan(regex).any?
163
+ File.exist?(file) && File.read(file).scan(regex).any?
170
164
  end
171
165
 
172
166
  def testing?