stairs 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14d977e07291f0a8476d22451cd1855c86b0c16a
4
- data.tar.gz: d3f3a5361958cab856dc009dd853cc266fb3fbee
3
+ metadata.gz: e22ee09384364f5f56adf9797d39f011a3cd9f99
4
+ data.tar.gz: a28246d9990d4e12ad7a7823ac386a3af1ef8d07
5
5
  SHA512:
6
- metadata.gz: a3916c63010aac63cee506da23393c36dae632ec722fa8dc430ba32df5eef14b71da1b70e3ab1022e08b5df3d9062f2871af71dd7d1b87db2bd7fab80f698a2a
7
- data.tar.gz: b4426ff951d58d03806047cf89bbf24fb42dd7ca5f66b78c2b79a5881128a30f4b2886b714b4acf496f2f9442ae0a68211404241166fc88fc787be7dd59faca6
6
+ metadata.gz: acecec427e75b4a218174046155a130837d6f69fd41b18ded6fe4b3de121088051b5339a4f107c83feb8d58c3435c05a10dff1cbbc8fc1a07b44d842fa1995d5
7
+ data.tar.gz: d0b036abcd2ea50371cf2ed69b6785f74ef79c0194b655c2e4604f9c6f9a9ecc310a20a2b9627eae1a37088a0874aa3595fc6a43e1eff20156f12111ba67ee8a
data/README.md CHANGED
@@ -44,19 +44,29 @@ require "stairs/tasks"
44
44
 
45
45
  ## Usage
46
46
 
47
+ ### Basic
48
+
47
49
  In an app with a `setup.rb`, just run the rake task:
48
50
 
49
51
  ```
50
52
  $ rake newb
51
53
  ```
52
54
 
55
+ ### Advanced
56
+
57
+ If you want more control, use the `stairs` command line utility:
58
+
59
+ ```
60
+ $ stairs --help
61
+ Usage: stairs [options]
62
+ --use-defaults Use defaults when available
63
+ ```
64
+
53
65
  ## Defining scripts
54
66
 
55
67
  A script composes many steps that setup a project.
56
68
 
57
69
  ```ruby
58
- bundle
59
-
60
70
  setup :secret_token
61
71
 
62
72
  setup :s3
@@ -104,11 +114,6 @@ write_line "more: false", "config/settings.yml"
104
114
 
105
115
  ### Misc helpers
106
116
 
107
- Run bundle to install gems
108
- ```ruby
109
- bundle
110
- ```
111
-
112
117
  Run rake tasks
113
118
  ```ruby
114
119
  rake "task_name"
@@ -166,9 +171,6 @@ this:
166
171
  $ rake newb
167
172
  Looks like you're using rbenv to manage environment variables. Is this correct? (Y/N): Y
168
173
  = Running script setup.rb
169
- == Running bundle
170
- ...
171
- == Completed bundle
172
174
  == Running S3
173
175
  AWS access key: 39u39d9u291
174
176
  AWS secret: 19jd920i10is0i01i0s01ks0kfknkje
data/bin/stairs ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "stairs"
5
+
6
+ Stairs.configure do |config|
7
+ OptionParser.new do |options|
8
+ options.banner = "Usage: stairs [options]"
9
+
10
+ options.on("--use-defaults", "Use defaults when available") do |value|
11
+ config.use_defaults = value
12
+ end
13
+ end.parse!
14
+ end
15
+
16
+ Stairs::Runner.new.run!
@@ -1,5 +1,10 @@
1
1
  module Stairs
2
2
  class Configuration
3
3
  attr_accessor :env_adapter
4
+ attr_accessor :use_defaults
5
+
6
+ def initialize
7
+ self.use_defaults = false
8
+ end
4
9
  end
5
10
  end
@@ -4,9 +4,19 @@ module Stairs
4
4
  description "Interactive prompt for configuring Stairs"
5
5
 
6
6
  def run!
7
+ if Stairs.configuration.use_defaults
8
+ use_recommended_adapter!
9
+ else
10
+ configure_env_adapter
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def configure_env_adapter
7
17
  choice prompt do |yes|
8
18
  if yes
9
- Stairs.configuration.env_adapter = recommended_adapter.new
19
+ use_recommended_adapter!
10
20
  else
11
21
  choice "Which would you prefer?", adapter_names do |name|
12
22
  adapter_class = Stairs::EnvAdapters::ADAPTERS[name.to_sym]
@@ -16,7 +26,9 @@ module Stairs
16
26
  end
17
27
  end
18
28
 
19
- private
29
+ def use_recommended_adapter!
30
+ Stairs.configuration.env_adapter = recommended_adapter.new
31
+ end
20
32
 
21
33
  def recommended_adapter
22
34
  @recommended_adapter ||= Stairs::EnvAdapters.recommended_adapter
@@ -0,0 +1,8 @@
1
+ module Stairs
2
+ class Runner
3
+ def run!
4
+ Stairs::InteractiveConfiguration.new.run!
5
+ Stairs::Script.new("setup.rb").run!
6
+ end
7
+ end
8
+ end
data/lib/stairs/step.rb CHANGED
@@ -40,8 +40,12 @@ module Stairs
40
40
  prompt << " (leave blank for #{options[:default]})" if options[:default]
41
41
  prompt << ": "
42
42
 
43
- Stairs::Util::CLI.collect(prompt.blue, required: required) ||
43
+ if Stairs.configuration.use_defaults && options[:default]
44
44
  options[:default]
45
+ else
46
+ Stairs::Util::CLI.collect(prompt.blue, required: required) ||
47
+ options[:default]
48
+ end
45
49
  end
46
50
 
47
51
  # Prompt user to make a choice
@@ -49,12 +53,6 @@ module Stairs
49
53
  Choice.new(*args, &block).run
50
54
  end
51
55
 
52
- def bundle
53
- stairs_info "== Running bundle"
54
- system "bundle"
55
- stairs_info "== Completed bundle"
56
- end
57
-
58
56
  def rake(task)
59
57
  stairs_info "== Running #{task}"
60
58
  system "rake #{task}"
data/lib/stairs/tasks.rb CHANGED
@@ -7,8 +7,7 @@ module Stairs
7
7
  def install!
8
8
  desc "Setup the project"
9
9
  task :newb do
10
- Stairs::InteractiveConfiguration.new.run!
11
- Stairs::Script.new("setup.rb").run!
10
+ Stairs::Runner.new.run!
12
11
  end
13
12
  end
14
13
  end
@@ -1,3 +1,3 @@
1
1
  module Stairs
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/stairs.rb CHANGED
@@ -10,6 +10,7 @@ module Stairs
10
10
  autoload :Configuration, "stairs/configuration"
11
11
  autoload :InteractiveConfiguration, "stairs/interactive_configuration"
12
12
  autoload :Util, "stairs/util"
13
+ autoload :Runner, "stairs/runner"
13
14
 
14
15
  class << self
15
16
  def configure
@@ -19,6 +20,10 @@ module Stairs
19
20
  def configuration
20
21
  @configuration ||= Configuration.new
21
22
  end
23
+
24
+ def reset_configuration!
25
+ @configuration = Configuration.new
26
+ end
22
27
  end
23
28
  end
24
29
 
@@ -8,5 +8,16 @@ describe Stairs::Configuration do
8
8
  subject.env_adapter = "test"
9
9
  expect(subject.env_adapter).to eq "test"
10
10
  end
11
+
12
+ describe "use_defaults to automatically use default values" do
13
+ it "defaults to false" do
14
+ expect(subject.use_defaults).to eq false
15
+ end
16
+
17
+ it "allows for configuration" do
18
+ subject.use_defaults = true
19
+ expect(subject.use_defaults).to eq true
20
+ end
21
+ end
11
22
  end
12
- end
23
+ end
@@ -32,5 +32,14 @@ describe Stairs::InteractiveConfiguration do
32
32
  follow_prompts("N", "dotenv") { subject.run! }
33
33
  expect(Stairs.configuration.env_adapter).to be_a Stairs::EnvAdapters::Dotenv
34
34
  end
35
+
36
+ context "when Stairs is configured to use defaults" do
37
+ before { Stairs.configuration.use_defaults = true }
38
+
39
+ it "uses the default adapter without asking" do
40
+ subject.run!
41
+ expect(Stairs.configuration.env_adapter).to be_a Stairs::EnvAdapters::Rbenv
42
+ end
43
+ end
35
44
  end
36
- end
45
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe Stairs::Runner do
4
+ describe "#run!" do
5
+ let(:script_double) { double("script", run!: true) }
6
+
7
+ before do
8
+ # Stub things as to not block IO
9
+ Stairs::InteractiveConfiguration.any_instance.stub :run!
10
+ Stairs::Script.any_instance.stub :run!
11
+ Stairs::Script.stub(:new).and_return(script_double)
12
+ end
13
+
14
+ it "runs the interactive configuration" do
15
+ Stairs::InteractiveConfiguration.any_instance.should_receive(:run!)
16
+ subject.run!
17
+ end
18
+
19
+ it "runs the setup.rb script" do
20
+ Stairs::Script.should_receive(:new).with("setup.rb").and_return(script_double)
21
+ script_double.should_receive(:run!)
22
+
23
+ subject.run!
24
+ end
25
+ end
26
+ end
@@ -121,6 +121,24 @@ describe Stairs::Step do
121
121
  end
122
122
  end
123
123
 
124
+ context "Stairs is configured to use defaults automatically" do
125
+ before { Stairs.configuration.use_defaults = true }
126
+
127
+ context "but no default is provided" do
128
+ it "prompts for input as usual" do
129
+ follow_prompts "here ya go" do
130
+ expect(subject.provide("Gimme")).to eq "here ya go"
131
+ end
132
+ end
133
+ end
134
+
135
+ context "and a default is provided" do
136
+ it "returns the default without prompting" do
137
+ expect(subject.provide("Gimme", default: "adefault")).to eq "adefault"
138
+ end
139
+ end
140
+ end
141
+
124
142
  context "with a default" do
125
143
  def call_method
126
144
  subject.provide "Gimme", default: "adefault"
@@ -213,25 +231,6 @@ describe Stairs::Step do
213
231
  end
214
232
  end
215
233
 
216
- describe "#bundle" do
217
- before { subject.stub system: true }
218
-
219
- it "outputs lead-in message" do
220
- output = capture_stdout { subject.bundle }
221
- expect(output).to include "== Running bundle"
222
- end
223
-
224
- it "runs bundle" do
225
- subject.should_receive(:system).with("bundle")
226
- subject.bundle
227
- end
228
-
229
- it "outputs completed message" do
230
- output = capture_stdout { subject.bundle }
231
- expect(output).to include "== Completed bundle"
232
- end
233
- end
234
-
235
234
  describe "#rake" do
236
235
  before { subject.stub system: true }
237
236
 
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,9 @@ RSpec.configure do |config|
16
16
  config.filter_run :focus
17
17
 
18
18
  config.include MockStdio
19
+ config.include ConfigurationHelper
19
20
 
20
21
  config.before(:all, &:silence_output)
21
22
  config.after(:all, &:enable_output)
23
+ config.after(:each, &:reset_configuration)
22
24
  end
@@ -0,0 +1,5 @@
1
+ module ConfigurationHelper
2
+ def reset_configuration
3
+ Stairs.reset_configuration!
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stairs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - patbenatar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-15 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -212,7 +212,8 @@ description: It's a pain to setup new developers. Stairs is a utility and framew
212
212
  prompts for everything else.
213
213
  email:
214
214
  - nick@gophilosophie.com
215
- executables: []
215
+ executables:
216
+ - stairs
216
217
  extensions: []
217
218
  extra_rdoc_files: []
218
219
  files:
@@ -225,6 +226,7 @@ files:
225
226
  - LICENSE.txt
226
227
  - README.md
227
228
  - Rakefile
229
+ - bin/stairs
228
230
  - lib/stairs.rb
229
231
  - lib/stairs/configuration.rb
230
232
  - lib/stairs/env_adapters.rb
@@ -233,6 +235,7 @@ files:
233
235
  - lib/stairs/env_adapters/rvm.rb
234
236
  - lib/stairs/interactive_configuration.rb
235
237
  - lib/stairs/railtie.rb
238
+ - lib/stairs/runner.rb
236
239
  - lib/stairs/script.rb
237
240
  - lib/stairs/step.rb
238
241
  - lib/stairs/steps.rb
@@ -250,12 +253,14 @@ files:
250
253
  - spec/lib/stairs/env_adapters/rvm_spec.rb
251
254
  - spec/lib/stairs/env_adapters_spec.rb
252
255
  - spec/lib/stairs/interactive_configuration_spec.rb
256
+ - spec/lib/stairs/runner_spec.rb
253
257
  - spec/lib/stairs/script_spec.rb
254
258
  - spec/lib/stairs/step_spec.rb
255
259
  - spec/lib/stairs/steps/secret_token_spec.rb
256
260
  - spec/lib/stairs/util/cli_spec.rb
257
261
  - spec/lib/stairs/util/file_mutation_spec.rb
258
262
  - spec/spec_helper.rb
263
+ - spec/support/configuration_helper.rb
259
264
  - stairs.gemspec
260
265
  - templates/postgresql/database.yml
261
266
  homepage: http://github.com/patbenatar/stairs
@@ -289,9 +294,11 @@ test_files:
289
294
  - spec/lib/stairs/env_adapters/rvm_spec.rb
290
295
  - spec/lib/stairs/env_adapters_spec.rb
291
296
  - spec/lib/stairs/interactive_configuration_spec.rb
297
+ - spec/lib/stairs/runner_spec.rb
292
298
  - spec/lib/stairs/script_spec.rb
293
299
  - spec/lib/stairs/step_spec.rb
294
300
  - spec/lib/stairs/steps/secret_token_spec.rb
295
301
  - spec/lib/stairs/util/cli_spec.rb
296
302
  - spec/lib/stairs/util/file_mutation_spec.rb
297
303
  - spec/spec_helper.rb
304
+ - spec/support/configuration_helper.rb