tomo 1.22.0 → 1.23.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37bdfaccc033913ce90f1f6efe579494272950799a735339e5f1ef17c4d10ce1
4
- data.tar.gz: e88924edaee4847ca1656dfe0381c275ef04d9d0f8ecd09499a5b98e0c71c211
3
+ metadata.gz: a2e5e093589de77525a3e23c89ade9506ab805e6714185f223b517c855e9833f
4
+ data.tar.gz: '0162796e298153c9d102c49806f9e14e13a7a0b163b520ce7044c4ce2eaa3942'
5
5
  SHA512:
6
- metadata.gz: 3ef5995f18228bb9c1631d89f88bbd63258f193c51a3ce40d506b5d56e4d9b4f2c5d030eef211db57ca81d57d4350f360e94ffb8979e00105c42ad8a644cfa7f
7
- data.tar.gz: '08eac8929502a70fdb7c4696b875a3ab58cd25783990bb5d2bcff124aff251b59330394063a8c0277dc28b937e1a270f96107e6169efd5824609b9af7a798f21'
6
+ metadata.gz: de7fcac2ea42c90e56a7517527a55c451c78fe7b681f833c2e42ea25a9002b64c439efbaf97d202931ea63aba73a4db4a18746e51f077b2add9fdfafbe406679
7
+ data.tar.gz: a8e0fa50d90ab152f06ffcac8e56a30411e643c7a6f871a07967e4fe0e395312648bb4aa97885f9f53136e677a89aa5e4aeec59d4c98f6b4255f2d355ec7531b
@@ -43,6 +43,7 @@ module Tomo
43
43
  end
44
44
 
45
45
  def prompt_for_environment(*, options)
46
+ options[:environment] ||= load_configuration(options).default_environment_name
46
47
  return unless options[:environment].nil?
47
48
 
48
49
  envs = environment_names(*, options)
@@ -13,7 +13,7 @@ module Tomo
13
13
 
14
14
  def configure_runtime(options, strict: true)
15
15
  config = load_configuration(options)
16
- env = options[:environment]
16
+ env = options[:environment] || config.default_environment_name
17
17
  env = config.environments.keys.first if env.nil? && !strict
18
18
  config = config.for_environment(env)
19
19
  config.settings.merge!(settings_from_env)
@@ -20,8 +20,8 @@ module Tomo
20
20
  self
21
21
  end
22
22
 
23
- def environment(name, &)
24
- environment = @config.environments[name.to_s] ||= Environment.new
23
+ def environment(name, default: false, &)
24
+ environment = @config.environments[name.to_s] ||= Environment.new(default:)
25
25
  EnvironmentBlock.new(environment).instance_eval(&)
26
26
  self
27
27
  end
@@ -5,10 +5,15 @@ module Tomo
5
5
  class Environment
6
6
  attr_accessor :hosts, :settings
7
7
 
8
- def initialize
8
+ def initialize(default: false)
9
+ @default = default
9
10
  @hosts = []
10
11
  @settings = {}
11
12
  end
13
+
14
+ def default?
15
+ !!@default
16
+ end
12
17
  end
13
18
  end
14
19
  end
@@ -3,7 +3,7 @@
3
3
  module Tomo
4
4
  class Configuration
5
5
  class UnknownEnvironmentError < Tomo::Error
6
- attr_accessor :name, :known_environments
6
+ attr_accessor :name, :known_environments, :default_environment
7
7
 
8
8
  def to_console
9
9
  known_environments.empty? ? no_envs : wrong_envs
@@ -27,7 +27,9 @@ module Tomo
27
27
  if suggestions.any?
28
28
  error + suggestions.to_console
29
29
  else
30
- envs = known_environments.map { |env| blue(" #{env}") }
30
+ envs = known_environments.map do |env|
31
+ [blue(" #{env}"), env == default_environment ? gray(" (default)") : nil].compact.join
32
+ end
31
33
  error + <<~ENVS
32
34
 
33
35
  The following environments are available:
@@ -38,6 +38,11 @@ module Tomo
38
38
  @task_filter = RoleBasedTaskFilter.new
39
39
  end
40
40
 
41
+ def default_environment_name
42
+ default_env = environments.one? ? environments.first : environments.find { |_, env| env.default? }
43
+ default_env&.first
44
+ end
45
+
41
46
  def for_environment(environment)
42
47
  validate_environment!(environment)
43
48
 
@@ -109,12 +114,14 @@ module Tomo
109
114
  settings.merge(environments[environ].settings)
110
115
  end
111
116
 
112
- def raise_no_environment_specified
113
- UnspecifiedEnvironmentError.raise_with(environments: environments.keys)
114
- end
117
+ def raise_no_environment_specified = UnspecifiedEnvironmentError.raise_with(environments: environments.keys)
115
118
 
116
119
  def raise_unknown_environment(environ)
117
- UnknownEnvironmentError.raise_with(name: environ, known_environments: environments.keys)
120
+ UnknownEnvironmentError.raise_with(
121
+ name: environ,
122
+ default_environment: default_environment_name,
123
+ known_environments: environments.keys
124
+ )
118
125
  end
119
126
  end
120
127
  end
data/lib/tomo/error.rb CHANGED
@@ -6,7 +6,7 @@ module Tomo
6
6
 
7
7
  include Colors
8
8
 
9
- def self.raise_with(message=nil, attributes)
9
+ def self.raise_with(message=nil, attributes) # rubocop:disable Style/OptionalArguments
10
10
  err = new(message)
11
11
  attributes.each { |attr, value| err.public_send(:"#{attr}=", value) }
12
12
  raise err
@@ -4,6 +4,9 @@ module Tomo::Plugin::Puma
4
4
  class Tasks < Tomo::TaskLibrary
5
5
  SystemdUnit = Struct.new(:name, :template, :path)
6
6
 
7
+ # Exposed to allow override during unit tests
8
+ def self.polling_delay = 1
9
+
7
10
  def setup_systemd # rubocop:disable Metrics/AbcSize
8
11
  linger_must_be_enabled!
9
12
 
@@ -90,7 +93,7 @@ module Tomo::Plugin::Puma
90
93
  def wait_until
91
94
  timeout = settings[:puma_check_timeout].to_i
92
95
  start = Time.now.to_i
93
- delay = 1
96
+ delay = self.class.polling_delay
94
97
 
95
98
  loop do
96
99
  sleep delay
@@ -99,7 +102,7 @@ module Tomo::Plugin::Puma
99
102
  elapsed = Time.now.to_i - start
100
103
  return false if elapsed >= timeout
101
104
 
102
- delay = [delay + 1, timeout - elapsed].min
105
+ delay = [delay + self.class.polling_delay, timeout - elapsed].min
103
106
  end
104
107
  end
105
108
 
@@ -37,11 +37,21 @@ module Tomo::Plugin::Rbenv
37
37
 
38
38
  unless ruby_installed?(ruby_version)
39
39
  logger.info("Installing ruby #{ruby_version} -- this may take several minutes")
40
- remote.run "CFLAGS=-O3 rbenv install #{ruby_version.shellescape} --verbose"
40
+ using_tmpdir do
41
+ remote.run "CFLAGS=-O3 rbenv install #{ruby_version.shellescape} --verbose"
42
+ end
41
43
  end
42
44
  remote.run "rbenv global #{ruby_version.shellescape}"
43
45
  end
44
46
 
47
+ def using_tmpdir(&)
48
+ tmpdir = paths.rbenv_tmpdir
49
+ return yield if tmpdir.nil?
50
+
51
+ remote.mkdir_p(tmpdir)
52
+ remote.env(TMPDIR: tmpdir, &)
53
+ end
54
+
45
55
  def ruby_installed?(version)
46
56
  versions = remote.capture("rbenv versions", raise_on_error: false)
47
57
  if versions.match?(/^\*?\s*#{Regexp.quote(version)}\s/)
@@ -7,7 +7,8 @@ module Tomo::Plugin
7
7
  extend Tomo::PluginDSL
8
8
 
9
9
  defaults bashrc_path: ".bashrc",
10
- rbenv_ruby_version: nil
10
+ rbenv_ruby_version: nil,
11
+ rbenv_tmpdir_path: nil
11
12
 
12
13
  tasks Tomo::Plugin::Rbenv::Tasks
13
14
  end
@@ -26,7 +26,7 @@ module Tomo
26
26
 
27
27
  case applicable_hosts.length
28
28
  when 1 then applicable_hosts.first.to_s
29
- when 2 then applicable_hosts.map(&:to_s).join(" and ")
29
+ when 2 then applicable_hosts.join(" and ")
30
30
  else
31
31
  "#{applicable_hosts.first} and #{applicable_hosts.length - 1} other hosts"
32
32
  end
@@ -120,7 +120,7 @@ class Unit
120
120
  end
121
121
  end
122
122
 
123
- class Service < Unit
123
+ class Service < Unit # rubocop:disable Style/OneClassPerFile
124
124
  def is_active # rubocop:disable Naming/PredicatePrefix
125
125
  exit(false) unless started?
126
126
  puts "active"
@@ -176,8 +176,8 @@ class Service < Unit
176
176
  end
177
177
 
178
178
  def with_detached_io
179
- null_in = File.open(File::NULL, "r")
180
- null_out = File.open(File::NULL, "w")
179
+ null_in = File.open(File::NULL, "r") # rubocop:disable Style/FileOpen
180
+ null_out = File.open(File::NULL, "w") # rubocop:disable Style/FileOpen
181
181
  $stdin.reopen(null_in)
182
182
  $stderr.reopen(null_out)
183
183
  $stdout.reopen(null_out)
data/lib/tomo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tomo
4
- VERSION = "1.22.0"
4
+ VERSION = "1.23.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.22.0
4
+ version: 1.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Brictson
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  requirements: []
191
- rubygems_version: 4.0.6
191
+ rubygems_version: 4.0.20
192
192
  specification_version: 4
193
193
  summary: A friendly CLI for deploying Rails apps ✨
194
194
  test_files: []