stairs 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: f617dda7fd3f43d796cde18e6cd509b7556ea2f4
4
- data.tar.gz: 8e2926466d8c307a8dbcd9be9a5a320e320495c5
3
+ metadata.gz: 7065dce0f1a914961380b69ee67aeab6ca1a3633
4
+ data.tar.gz: b9adf5378fc447b10dd8a4cb9e349b2d56faff3d
5
5
  SHA512:
6
- metadata.gz: eb0910186b1a3886ecff848942bb6c119cc58f7017fc74b0720ccf142aa0495eba3a0ba3461de3d9af65276fc3272da90b6d769067bc299b8525e35efe0ad9e2
7
- data.tar.gz: fc18be8d140dbd7c1c1b07d3252f3b7a389e0826d855693120b86c6edc30a7fdb424a3fb9ab1f8d449eaa79aa59a5554bbdffc99eb1a2201066c3f1f08081978
6
+ metadata.gz: 8838ad2217b046c6fcc40fa578df6ce8e6b282d1752224d76aab26ee437e08e72dc0b5d02af85cfddca0c9f103eedc4aebf907429928dd6c05ac94bc7d8b5cfc
7
+ data.tar.gz: f6ba56450cf0aafb9156f0ca625eadf3d3c4fa8374b6a25e3ea8a23489b5a932c6949b5c18a48062eb666c7df25a35e0e7218fd0429d7b863149ebb91881e281
data/README.md CHANGED
@@ -30,14 +30,20 @@ A script composes many steps that setup a project. __Note:__ optional steps are
30
30
  not yet implemented.
31
31
 
32
32
  ```ruby
33
+ bundle
34
+
33
35
  setup :secret_token
34
36
 
35
37
  setup :s3
36
38
  setup :zencoder, required: false
37
39
 
38
- env "CHECK_IT", provide "Cool check it value"
40
+ setup :misc do
41
+ env "CHECK_IT", provide "Cool check it value"
42
+ end
43
+
44
+ rake "db:setup"
39
45
 
40
- puts "Sweet you're good to go. Just run `rails s` and `sidekiq` to get rolling!"
46
+ finish "Just run rails s and sidekiq to get rolling!"
41
47
  ```
42
48
 
43
49
  ### Example CLI
@@ -47,20 +53,32 @@ is desired future functionality (bundle/db tasks, spacing, last words).
47
53
 
48
54
  ```
49
55
  $ rake newb
50
- ... bundle install
51
- ... db setup + seed
56
+ Looks like you're using rbenv to manage environment variables. Is this correct? (Y/N): Y
57
+
58
+ = Running script setup.rb
59
+
60
+ == Running bundle
61
+ ...
62
+ == Completed bundle
52
63
 
53
- == Starting S3 Setup
64
+ == Running S3
54
65
  AWS access key: 39u39d9u291
55
66
  AWS secret: 19jd920i10is0i01i0s01ks0kfknkje
56
67
  Do you have an existing bucket? (Y/N): Y
57
68
  Bucket name (leave blank for app-dev): my-cool-bucket
69
+ == Completed S3
58
70
 
59
71
  == Starting Zencoder
60
72
  This step is optional, would you like to perform it? (Y/N): N
73
+ == Completed Zencoder
61
74
 
62
- == Starting misc
75
+ == Starting Misc
63
76
  Cool check it value: w00t
77
+ == Completed Misc
78
+
79
+ == Running db:setup
80
+ ...
81
+ == Completed db:setup
64
82
 
65
83
  == All done!
66
84
  Run rails s and sidekiq to get rolling!
@@ -95,14 +113,28 @@ write "awesome: true", "config/settings.yml"
95
113
  write_line "more: false", "config/settings.yml"
96
114
  ```
97
115
 
98
- ### Defining setup steps
116
+ ### Misc helpers
99
117
 
100
- __Note:__ this block syntax is not yet implemented, use predefined steps for
101
- now.
118
+ Run bundle to install gems
119
+ ```ruby
120
+ bundle
121
+ ```
122
+
123
+ Run rake tasks
124
+ ```ruby
125
+ rake "task_name"
126
+ ```
127
+
128
+ Display a message when setup completes
129
+ ```ruby
130
+ finish "Now that you're done, go have a drink!"
131
+ ```
132
+
133
+ ### Defining setup steps
102
134
 
103
135
  ```ruby
104
136
  setup :a_cool_service do
105
- ## ..
137
+ # ...
106
138
  end
107
139
  ```
108
140
 
data/lib/stairs/script.rb CHANGED
@@ -6,7 +6,7 @@ module Stairs
6
6
  end
7
7
 
8
8
  def run!
9
- puts "= Running script #{filename}"
9
+ puts "= Running script #{filename}".light_black
10
10
  run
11
11
  end
12
12
 
data/lib/stairs/step.rb CHANGED
@@ -3,20 +3,31 @@ require "highline/import"
3
3
  module Stairs
4
4
  class Step
5
5
  def run!
6
- puts "== Running #{self.class.title}"
6
+ stairs_info "== Running #{step_title}"
7
7
  run
8
+ stairs_info "== Completed #{step_title}"
8
9
  end
9
10
 
11
+ attr_writer :step_title, :step_description
12
+
10
13
  private
11
14
 
12
- class_attribute :title, :description
15
+ class_attribute :step_title, :step_description
13
16
 
14
17
  def self.title(title)
15
- self.title = title
18
+ self.step_title = title
16
19
  end
17
20
 
18
21
  def self.description(description)
19
- self.description = description
22
+ self.step_description = description
23
+ end
24
+
25
+ def step_title
26
+ @step_title || self.class.step_title
27
+ end
28
+
29
+ def step_description
30
+ @step_description || self.class.step_description
20
31
  end
21
32
 
22
33
  # Prompt user to provide input
@@ -27,7 +38,7 @@ module Stairs
27
38
  prompt << " (leave blank for #{options[:default]})" if options[:default]
28
39
  prompt << ": "
29
40
 
30
- response = ask(prompt) { |q| q.validate = /\S+/ if required }
41
+ response = ask(prompt.blue) { |q| q.validate = /\S+/ if required }
31
42
  response.present? ? response : options[:default]
32
43
  end
33
44
 
@@ -35,7 +46,7 @@ module Stairs
35
46
  # TODO shouldn't care about case
36
47
  def choice(question, choices=["Y", "N"])
37
48
  prompt = "#{question} (#{choices.join("/")}): "
38
- response = ask(prompt) { |q| q.in = choices }
49
+ response = ask(prompt.blue) { |q| q.in = choices }
39
50
 
40
51
  case response
41
52
  when "Y"
@@ -48,7 +59,19 @@ module Stairs
48
59
  response
49
60
  end
50
61
 
51
- # Set or update env var in .rbenv-vars
62
+ def bundle
63
+ stairs_info "== Running bundle"
64
+ system "bundle"
65
+ stairs_info "== Completed bundle"
66
+ end
67
+
68
+ def rake(task)
69
+ stairs_info "== Running #{task}"
70
+ system "rake #{task}"
71
+ stairs_info "== Completed #{task}"
72
+ end
73
+
74
+ # Set or update env var
52
75
  def env(name, value)
53
76
  Stairs.configuration.env_adapter.set name, value
54
77
  end
@@ -64,10 +87,27 @@ module Stairs
64
87
  end
65
88
 
66
89
  # Embed a step where step_name is a symbol that can be resolved to a class
67
- # in Stairs::Steps
68
- def setup(step_name)
69
- klass = "Stairs::Steps::#{step_name.to_s.camelize}".constantize
70
- klass.new.run!
90
+ # in Stairs::Steps or a block is provided to be executed in an instance
91
+ # of Step
92
+ def setup(step_name, &block)
93
+ if block_given?
94
+ Step.new.tap do |step|
95
+ step.define_singleton_method :run, &block
96
+ step.step_title = step_name.to_s.titleize
97
+ end.run!
98
+ else
99
+ klass = "Stairs::Steps::#{step_name.to_s.camelize}".constantize
100
+ klass.new.run!
101
+ end
102
+ end
103
+
104
+ def finish(message)
105
+ puts "== All done!".green
106
+ puts message.green
107
+ end
108
+
109
+ def stairs_info(message)
110
+ puts message.light_black
71
111
  end
72
112
  end
73
113
  end
@@ -1,3 +1,3 @@
1
1
  module Stairs
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/stairs.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "stairs/version"
2
2
  require "active_support/core_ext"
3
+ require "colorize"
3
4
 
4
5
  module Stairs
5
6
  autoload :Step, "stairs/step"
data/stairs.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency "highline", "~> 1.6.20"
25
25
  spec.add_dependency "activesupport", ">= 3.2.0"
26
+ spec.add_dependency "colorize", "~> 0.6.0"
26
27
  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.2.0
4
+ version: 0.3.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-10-29 00:00:00.000000000 Z
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.0
69
83
  description: A DSL and collection of plugins for easy setup of projects on new development
70
84
  environments.
71
85
  email: