stairs 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -36
- data/.travis.yml +6 -2
- data/Guardfile +2 -2
- data/Rakefile +4 -4
- data/bin/stairs +10 -10
- data/lib/stairs.rb +13 -13
- data/lib/stairs/env_adapters.rb +6 -6
- data/lib/stairs/env_adapters/dotenv.rb +3 -3
- data/lib/stairs/env_adapters/rbenv.rb +3 -3
- data/lib/stairs/env_adapters/rvm.rb +3 -3
- data/lib/stairs/interactive_configuration.rb +11 -11
- data/lib/stairs/railtie.rb +1 -1
- data/lib/stairs/runner.rb +2 -2
- data/lib/stairs/step.rb +20 -17
- data/lib/stairs/steps.rb +3 -3
- data/lib/stairs/steps/facebook.rb +6 -6
- data/lib/stairs/steps/postgresql.rb +11 -11
- data/lib/stairs/steps/secret_key_base.rb +4 -4
- data/lib/stairs/tasks.rb +2 -2
- data/lib/stairs/util.rb +2 -2
- data/lib/stairs/util/cli.rb +3 -4
- data/lib/stairs/util/file_mutation.rb +10 -10
- data/lib/stairs/version.rb +1 -1
- data/spec/lib/configuration_spec.rb +8 -8
- data/spec/lib/stairs/env_adapters/dotenv_spec.rb +20 -20
- data/spec/lib/stairs/env_adapters/rbenv_spec.rb +22 -22
- data/spec/lib/stairs/env_adapters/rvm_spec.rb +22 -22
- data/spec/lib/stairs/env_adapters_spec.rb +12 -14
- data/spec/lib/stairs/interactive_configuration_spec.rb +27 -20
- data/spec/lib/stairs/runner_spec.rb +18 -14
- data/spec/lib/stairs/script_spec.rb +13 -14
- data/spec/lib/stairs/step_spec.rb +225 -189
- data/spec/lib/stairs/steps/secret_key_base_spec.rb +7 -5
- data/spec/lib/stairs/util/cli_spec.rb +29 -29
- data/spec/lib/stairs/util/file_mutation_spec.rb +46 -46
- data/spec/spec_helper.rb +6 -8
- data/stairs.gemspec +28 -23
- metadata +22 -23
- data/spec/support/configuration_helper.rb +0 -5
@@ -1,8 +1,8 @@
|
|
1
1
|
module Stairs
|
2
2
|
module Steps
|
3
3
|
class Postgresql < Stairs::Step
|
4
|
-
title
|
5
|
-
description
|
4
|
+
title 'PostgreSQL'
|
5
|
+
description 'Setup database.yml for PostgreSQL'
|
6
6
|
|
7
7
|
def run
|
8
8
|
set_database_name
|
@@ -10,36 +10,36 @@ module Stairs
|
|
10
10
|
set_username
|
11
11
|
set_password
|
12
12
|
|
13
|
-
write contents,
|
13
|
+
write contents, 'config/database.yml'
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def set_database_name
|
19
19
|
contents.gsub!(
|
20
|
-
|
21
|
-
provide(
|
20
|
+
'{{database_name}}',
|
21
|
+
provide('Database name', default: "#{app_name}_development")
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
25
|
def set_test_database_name
|
26
26
|
contents.gsub!(
|
27
|
-
|
28
|
-
provide(
|
27
|
+
'{{test_database_name}}',
|
28
|
+
provide('Test database name', default: "#{app_name}_test")
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
32
|
def set_username
|
33
33
|
contents.gsub!(
|
34
|
-
|
35
|
-
provide(
|
34
|
+
'{{username}}',
|
35
|
+
provide('User', default: `whoami`.strip)
|
36
36
|
)
|
37
37
|
end
|
38
38
|
|
39
39
|
def set_password
|
40
40
|
contents.gsub!(
|
41
|
-
|
42
|
-
provide(
|
41
|
+
'{{password}}',
|
42
|
+
provide('Password', default: '')
|
43
43
|
)
|
44
44
|
end
|
45
45
|
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require 'securerandom'
|
2
2
|
|
3
3
|
module Stairs
|
4
4
|
module Steps
|
5
5
|
class SecretKeyBase < Step
|
6
|
-
title
|
7
|
-
description
|
6
|
+
title 'Secret Token'
|
7
|
+
description 'Generate a secure random secret token'
|
8
8
|
|
9
9
|
def run
|
10
|
-
env
|
10
|
+
env 'SECRET_KEY_BASE', SecureRandom.hex(64)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/stairs/tasks.rb
CHANGED
data/lib/stairs/util.rb
CHANGED
data/lib/stairs/util/cli.rb
CHANGED
@@ -13,17 +13,16 @@ module Stairs
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
private
|
17
|
-
|
18
16
|
class Collector
|
19
|
-
def initialize(prompt, options={}, &block)
|
17
|
+
def initialize(prompt, options = {}, &block)
|
20
18
|
@prompt = prompt
|
21
19
|
@options = options.reverse_merge required: true
|
22
20
|
@validator = block
|
23
21
|
end
|
24
22
|
|
25
23
|
def run
|
26
|
-
times
|
24
|
+
times = 0
|
25
|
+
value = nil
|
27
26
|
|
28
27
|
until valid?(value, times)
|
29
28
|
value = CLI.get(prompt.blue)
|
@@ -3,7 +3,7 @@ module Stairs
|
|
3
3
|
module FileMutation
|
4
4
|
class << self
|
5
5
|
def replace_or_append(pattern, string, filename)
|
6
|
-
if File.
|
6
|
+
if File.exist? filename
|
7
7
|
contents = File.read filename
|
8
8
|
if contents =~ pattern
|
9
9
|
contents.sub! pattern, string
|
@@ -16,27 +16,27 @@ module Stairs
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def remove(pattern, filename)
|
19
|
-
return unless File.
|
19
|
+
return unless File.exist? filename
|
20
20
|
|
21
21
|
contents = File.read filename
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
return unless contents =~ pattern
|
23
|
+
|
24
|
+
contents.slice!(pattern)
|
25
|
+
write contents, filename
|
26
26
|
end
|
27
27
|
|
28
28
|
def write_line(string, filename)
|
29
|
-
File.open filename,
|
29
|
+
File.open filename, 'a+' do |file|
|
30
30
|
# ensure file ends with newline before appending
|
31
|
-
last_line = file.each_line.reduce(
|
32
|
-
file.puts
|
31
|
+
last_line = file.each_line.reduce('') { |_m, l| l }
|
32
|
+
file.puts '' unless last_line == '' || last_line =~ /(.*)\n/
|
33
33
|
|
34
34
|
file.puts string
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def write(string, filename)
|
39
|
-
File.open filename,
|
39
|
+
File.open filename, 'w+' do |file|
|
40
40
|
file.puts string
|
41
41
|
end
|
42
42
|
end
|
data/lib/stairs/version.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stairs::Configuration do
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
subject.env_adapter =
|
9
|
-
expect(subject.env_adapter).to eq
|
6
|
+
describe 'attributes' do
|
7
|
+
it 'allows for configuration of env_adapter' do
|
8
|
+
subject.env_adapter = 'test'
|
9
|
+
expect(subject.env_adapter).to eq 'test'
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
12
|
+
describe 'use_defaults to automatically use default values' do
|
13
|
+
it 'defaults to false' do
|
14
14
|
expect(subject.use_defaults).to eq false
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it 'allows for configuration' do
|
18
18
|
subject.use_defaults = true
|
19
19
|
expect(subject.use_defaults).to eq true
|
20
20
|
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stairs::EnvAdapters::Dotenv do
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
describe
|
7
|
-
context
|
8
|
-
before { stub_const
|
6
|
+
describe '.present?' do
|
7
|
+
context 'when rvm is installed' do
|
8
|
+
before { stub_const 'Dotenv', double('dotenv') }
|
9
9
|
|
10
|
-
it
|
11
|
-
expect(described_class.present?).to
|
10
|
+
it 'returns true' do
|
11
|
+
expect(described_class.present?).to eq true
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context
|
15
|
+
context 'when rvm is not installed' do
|
16
16
|
before { Object.send(:remove_const, :Dotenv) if defined? ::Dotenv }
|
17
17
|
|
18
|
-
it
|
19
|
-
expect(described_class.present?).to
|
18
|
+
it 'returns true' do
|
19
|
+
expect(described_class.present?).to eq false
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
25
|
-
it
|
26
|
-
name =
|
27
|
-
value =
|
24
|
+
describe '#set' do
|
25
|
+
it 'delegates to the well tested FileMutation util' do
|
26
|
+
name = 'VAR_NAME'
|
27
|
+
value = 'the_value'
|
28
28
|
|
29
|
-
Stairs::Util::FileMutation.
|
29
|
+
expect(Stairs::Util::FileMutation).to receive(:replace_or_append).with(
|
30
30
|
Regexp.new("^#{name}=(.*)$"),
|
31
31
|
"#{name}=#{value}",
|
32
|
-
|
32
|
+
'.env'
|
33
33
|
)
|
34
34
|
|
35
35
|
subject.set(name, value)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
describe
|
40
|
-
it
|
41
|
-
Stairs::Util::FileMutation.
|
39
|
+
describe '#unset' do
|
40
|
+
it 'delegates to the well tested FileMutation util' do
|
41
|
+
expect(Stairs::Util::FileMutation).to receive(:remove).with(
|
42
42
|
Regexp.new("^SOMETHING=(.*)\n"),
|
43
|
-
|
43
|
+
'.env'
|
44
44
|
)
|
45
|
-
subject.unset
|
45
|
+
subject.unset 'SOMETHING'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stairs::EnvAdapters::Rbenv do
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
describe
|
7
|
-
before { described_class.
|
6
|
+
describe '.present?' do
|
7
|
+
before { expect(described_class).to receive(:`).with('which rbenv-vars') }
|
8
8
|
|
9
|
-
context
|
10
|
-
before {
|
9
|
+
context 'when rbenv-vars is installed' do
|
10
|
+
before { allow($CHILD_STATUS).to receive(:success?).and_return(true) }
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(described_class.present?).to
|
12
|
+
it 'returns true' do
|
13
|
+
expect(described_class.present?).to eq true
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
18
|
-
before {
|
17
|
+
context 'when rbenv-vars is not installed' do
|
18
|
+
before { allow($CHILD_STATUS).to receive(:success?).and_return(false) }
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(described_class.present?).to
|
20
|
+
it 'returns true' do
|
21
|
+
expect(described_class.present?).to eq false
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
name =
|
29
|
-
value =
|
26
|
+
describe '#set' do
|
27
|
+
it 'delegates to the well tested FileMutation util' do
|
28
|
+
name = 'VAR_NAME'
|
29
|
+
value = 'the_value'
|
30
30
|
|
31
|
-
Stairs::Util::FileMutation.
|
31
|
+
expect(Stairs::Util::FileMutation).to receive(:replace_or_append).with(
|
32
32
|
Regexp.new("^#{name}=(.*)$"),
|
33
33
|
"#{name}=#{value}",
|
34
|
-
|
34
|
+
'.rbenv-vars'
|
35
35
|
)
|
36
36
|
|
37
37
|
subject.set(name, value)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe
|
42
|
-
it
|
43
|
-
Stairs::Util::FileMutation.
|
41
|
+
describe '#unset' do
|
42
|
+
it 'delegates to the well tested FileMutation util' do
|
43
|
+
expect(Stairs::Util::FileMutation).to receive(:remove).with(
|
44
44
|
Regexp.new("^SOMETHING=(.*)\n"),
|
45
|
-
|
45
|
+
'.rbenv-vars'
|
46
46
|
)
|
47
|
-
subject.unset
|
47
|
+
subject.unset 'SOMETHING'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stairs::EnvAdapters::RVM do
|
4
4
|
subject { described_class.new }
|
5
5
|
|
6
|
-
describe
|
7
|
-
before { described_class.
|
6
|
+
describe '.present?' do
|
7
|
+
before { expect(described_class).to receive(:`).with('which rvm') }
|
8
8
|
|
9
|
-
context
|
10
|
-
before {
|
9
|
+
context 'when rvm is installed' do
|
10
|
+
before { allow($CHILD_STATUS).to receive(:success?).and_return(true) }
|
11
11
|
|
12
|
-
it
|
13
|
-
expect(described_class.present?).to
|
12
|
+
it 'returns true' do
|
13
|
+
expect(described_class.present?).to eq true
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context
|
18
|
-
before {
|
17
|
+
context 'when rvm is not installed' do
|
18
|
+
before { allow($CHILD_STATUS).to receive(:success?).and_return(false) }
|
19
19
|
|
20
|
-
it
|
21
|
-
expect(described_class.present?).to
|
20
|
+
it 'returns true' do
|
21
|
+
expect(described_class.present?).to eq false
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
name =
|
29
|
-
value =
|
26
|
+
describe '#set' do
|
27
|
+
it 'delegates to the well tested FileMutation util' do
|
28
|
+
name = 'VAR_NAME'
|
29
|
+
value = 'the_value'
|
30
30
|
|
31
|
-
Stairs::Util::FileMutation.
|
31
|
+
expect(Stairs::Util::FileMutation).to receive(:replace_or_append).with(
|
32
32
|
Regexp.new("^export #{name}=(.*)$"),
|
33
33
|
"export #{name}=#{value}",
|
34
|
-
|
34
|
+
'.rvmrc'
|
35
35
|
)
|
36
36
|
|
37
37
|
subject.set(name, value)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe
|
42
|
-
it
|
43
|
-
Stairs::Util::FileMutation.
|
41
|
+
describe '#unset' do
|
42
|
+
it 'delegates to the well tested FileMutation util' do
|
43
|
+
expect(Stairs::Util::FileMutation).to receive(:remove).with(
|
44
44
|
Regexp.new("^export SOMETHING=(.*)\n"),
|
45
|
-
|
45
|
+
'.rvmrc'
|
46
46
|
)
|
47
|
-
subject.unset
|
47
|
+
subject.unset 'SOMETHING'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -1,28 +1,26 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Stairs::EnvAdapters do
|
4
4
|
subject { described_class }
|
5
|
-
let(:present_adapter) { double(
|
6
|
-
let(:other_adapter) { double(
|
7
|
-
let(:another_adapter) { double(
|
5
|
+
let(:present_adapter) { double('adapter', present?: true) }
|
6
|
+
let(:other_adapter) { double('adapter', present?: false) }
|
7
|
+
let(:another_adapter) { double('adapter', present?: false) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
stub_const
|
11
|
-
|
12
|
-
|
13
|
-
three: another_adapter
|
14
|
-
}
|
10
|
+
stub_const 'Stairs::EnvAdapters::ADAPTERS', one: other_adapter,
|
11
|
+
two: present_adapter,
|
12
|
+
three: another_adapter
|
15
13
|
end
|
16
14
|
|
17
|
-
describe
|
18
|
-
it
|
15
|
+
describe '.recommended_adapter' do
|
16
|
+
it 'returns the first adapter to be `present?`' do
|
19
17
|
expect(described_class.recommended_adapter).to eq present_adapter
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
23
|
-
describe
|
24
|
-
it
|
21
|
+
describe '.name_for_adapter_class' do
|
22
|
+
it 'returns the name' do
|
25
23
|
expect(described_class.name_for_adapter_class(present_adapter)).to eq :two
|
26
24
|
end
|
27
25
|
end
|
28
|
-
end
|
26
|
+
end
|