stairs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33a677ee365b86ecafb40d9c1edf90ac58e1bfb2
4
+ data.tar.gz: 338a869ea99daa99b2169d68c50c332e5267082a
5
+ SHA512:
6
+ metadata.gz: dc5721e3e681b11129b0128fbeb61b90c0e3327e6e03b65e6b4cc3769904e7d0022715ced79b38924bdd5d7d3ac79da32c43053a26213185587f01c6822db645
7
+ data.tar.gz: 29762a735866dd6d8b064959ef751b5a8563f12967d5113f63ee7cb5de86a7dce649aa639251f02bdeb273b8639028151b591a1f28b69950d650e5ae2c37df40
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stairs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 patbenatar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Stairs
2
+
3
+ A DSL and collection of plugins for easy setup of projects on new development
4
+ environments.
5
+
6
+ ## Setup
7
+
8
+ 1. Install gem `stairs`
9
+
10
+ 1. Require tasks in Rakefile
11
+ ```ruby
12
+ require "stairs/tasks"
13
+ ```
14
+
15
+ 1. Define `setup.rb` in the root of your project
16
+
17
+ ## Usage
18
+
19
+ In an app with a `setup.rb`, just run the rake task:
20
+
21
+ ```
22
+ $ rake newb
23
+ ```
24
+
25
+ ## Defining scripts
26
+
27
+ A script composes many steps that setup a project.
28
+
29
+ ```ruby
30
+ setup :secret_token
31
+
32
+ setup :s3
33
+ setup :zencoder, required: false
34
+
35
+ env "CHECK_IT", provide "Cool check it value"
36
+
37
+ puts "Sweet you're good to go. Just run `rails s` and `sidekiq` to get rolling!"
38
+ ```
39
+
40
+ ### Example CLI
41
+
42
+ Given the above script, the CLI would look like this:
43
+
44
+ ```
45
+ $ rake newb
46
+ ... bundle install
47
+ ... db setup + seed
48
+
49
+ == Starting S3 Setup
50
+ AWS access key: 39u39d9u291
51
+ AWS secret: 19jd920i10is0i01i0s01ks0kfknkje
52
+ Do you have an existing bucket? (Y/N): Y
53
+ Bucket name (leave blank for app-dev): my-cool-bucket
54
+
55
+ == Starting Zencoder
56
+ This step is optional, would you like to perform it? (Y/N): N
57
+
58
+ == Starting misc
59
+ Cool check it value: w00t
60
+
61
+ == All done!
62
+ Run rails s and sidekiq to get rolling!
63
+ ```
64
+
65
+ ## DSL
66
+
67
+ ### Collecting values
68
+ ```ruby
69
+ value = provide "Something"
70
+ value = provide "Another", required: false
71
+ provide "More", default: "a-default"
72
+ ```
73
+
74
+ ### Asking questions
75
+ ```ruby
76
+ i_should = choice "Should I?"
77
+ choice "Should I?" do |yes|
78
+ do_something if yes
79
+ end
80
+ dinner = choice "Meat or vegetables?", ["Meat", "Vegetables"]
81
+ ```
82
+
83
+ ### Setting env vars
84
+ ```ruby
85
+ env "NAME", value
86
+ ```
87
+
88
+ ### Writing files
89
+ ```ruby
90
+ write "awesome: true", "config/settings.yml"
91
+ write_line "more: false", "config/settings.yml"
92
+ ```
93
+
94
+ ### Defining setup steps
95
+ ```ruby
96
+ setup :a_cool_service do
97
+ ## ..
98
+ end
99
+ ```
100
+
101
+ #### Using predefined steps
102
+ ```ruby
103
+ setup :s3
104
+ ```
105
+
106
+ ## Plugins for common setups
107
+
108
+ ```ruby
109
+ require "fog"
110
+ class S3Setup < Stairs::Step
111
+ title "S3"
112
+ description "Setup AWS tokens and bucket"
113
+
114
+ def run
115
+ @key = provide "AWS access key"
116
+ @secret = provide "AWS secret"
117
+
118
+ choice "Do you have an existing bucket?" do |yes|
119
+ env "S3_BUCKET", if yes
120
+ provide "Bucket name", default: "app-dev"
121
+ else
122
+ create_bucket
123
+ end
124
+ end
125
+
126
+ env "AWS_ACCESS_KEY", @key
127
+ env "AWS_SECRET", @secret
128
+ end
129
+
130
+ private
131
+
132
+ def create_bucket
133
+ # use @key and @secret to create bucket via API
134
+ end
135
+ end
136
+ ```
137
+
138
+ ## To think about...
139
+
140
+ * How to manage gem dependencies (S3Setup for example requires fog to be
141
+ installed)
142
+
143
+ ## Contributing
144
+
145
+ 1. Fork it
146
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
147
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
148
+ 4. Push to the branch (`git push origin my-new-feature`)
149
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ module Stairs
2
+ class Script
3
+ def initialize(filename)
4
+ @filename = filename
5
+ @script = File.read(@filename)
6
+ end
7
+
8
+ def run!
9
+ puts "= Running script #{filename}"
10
+ run
11
+ end
12
+
13
+ def run
14
+ Step.new.instance_eval(script)
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :script, :filename
20
+ end
21
+ end
@@ -0,0 +1,88 @@
1
+ require "highline/import"
2
+
3
+ module Stairs
4
+ class Step
5
+ def run!
6
+ puts "== Running #{self.class.title}"
7
+ run
8
+ end
9
+
10
+ private
11
+
12
+ class_attribute :title, :description
13
+
14
+ def self.title(title)
15
+ self.title = title
16
+ end
17
+
18
+ def self.description(description)
19
+ self.description = description
20
+ end
21
+
22
+ # Prompt user to provide input
23
+ def provide(prompt, options={})
24
+ options.reverse_merge! required: true, default: nil
25
+ required = options[:required] && !options[:default]
26
+
27
+ prompt << " (leave blank for #{options[:default]})" if options[:default]
28
+ prompt << ": "
29
+
30
+ response = ask(prompt) { |q| q.validate = /\S+/ if required }
31
+ response.present? ? response : options[:default]
32
+ end
33
+
34
+ # Prompt user to make a choice
35
+ # TODO shouldn't care about case
36
+ def choice(question, choices=["Y", "N"])
37
+ prompt = "#{question} (#{choices.join("/")}): "
38
+ response = ask(prompt) { |q| q.in = choices }
39
+
40
+ case response
41
+ when "Y"
42
+ response = true
43
+ when "N"
44
+ response = false
45
+ end
46
+
47
+ yield response if block_given?
48
+ response
49
+ end
50
+
51
+ # Set or update env var in .rbenv-vars
52
+ def env(name, value)
53
+ string = "#{name}=#{value}"
54
+
55
+ if File.exists? ".rbenv-vars"
56
+ contents = File.read ".rbenv-vars"
57
+ regexp = Regexp.new "^#{name}=(.*)$"
58
+ if contents.index regexp
59
+ contents.sub! regexp, string
60
+ write contents, ".rbenv-vars"
61
+ return
62
+ end
63
+ end
64
+
65
+ write_line string, ".rbenv-vars"
66
+ end
67
+
68
+ # Replace contents of file
69
+ def write(string, filename)
70
+ File.truncate filename, 0 if File.exists? filename
71
+ write_line string, filename
72
+ end
73
+
74
+ # Append line to file
75
+ def write_line(string, filename)
76
+ File.open filename, "a" do |file|
77
+ file.puts string
78
+ end
79
+ end
80
+
81
+ # Embed a step where step_name is a symbol that can be resolved to a class
82
+ # in Stairs::Steps
83
+ def setup(step_name)
84
+ klass = "Stairs::Steps::#{step_name.to_s.camelize}".constantize
85
+ klass.new.run!
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,14 @@
1
+ module Stairs
2
+ module Steps
3
+ class S3 < Step
4
+ title "S3"
5
+ description "Setup AWS and S3 bucket access"
6
+
7
+ def run
8
+ env "AWS_ACCESS_KEY_ID", provide("AWS Access Key ID")
9
+ env "AWS_SECRET_ACCESS_KEY", provide("AWS Secret Access Key")
10
+ env "AWS_S3_BUCKET", provide("S3 Bucket name")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require "securerandom"
2
+
3
+ module Stairs
4
+ module Steps
5
+ class SecretToken < Step
6
+ title "Secret Token"
7
+ description "Generate a secure random secret token"
8
+
9
+ def run
10
+ env "SECRET_TOKEN", SecureRandom.hex(64)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ module Stairs
2
+ module Steps
3
+ autoload :SecretToken, "stairs/steps/secret_token"
4
+ autoload :S3, "stairs/steps/s3"
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ require "stairs"
2
+
3
+ module Stairs
4
+ class Tasks
5
+ include Rake::DSL
6
+
7
+ def install!
8
+ desc "Setup the project"
9
+ task :newb do
10
+ Stairs::Script.new("setup.rb").run!
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ Stairs::Tasks.new.install!
@@ -0,0 +1,3 @@
1
+ module Stairs
2
+ VERSION = "0.0.1"
3
+ end
data/lib/stairs.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "stairs/version"
2
+ require "active_support/core_ext"
3
+
4
+ module Stairs
5
+ autoload :Step, "stairs/step"
6
+ autoload :Script, "stairs/script"
7
+ autoload :Steps, "stairs/steps"
8
+ end
data/stairs.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stairs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stairs"
8
+ spec.version = Stairs::VERSION
9
+ spec.authors = ["patbenatar"]
10
+ spec.email = ["nick@gophilosophie.com"]
11
+ spec.description = "A DSL and collection of plugins for easy setup of projects on new development environments."
12
+ spec.summary = "A DSL and collection of plugins for easy setup of projects on new development environments."
13
+ spec.homepage = "http://github.com/patbenatar/stairs"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "highline", "~> 1.6.20"
25
+ spec.add_dependency "activesupport", "> 3.2.0"
26
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stairs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - patbenatar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.20
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.20
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>'
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>'
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ description: A DSL and collection of plugins for easy setup of projects on new development
70
+ environments.
71
+ email:
72
+ - nick@gophilosophie.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/stairs.rb
83
+ - lib/stairs/script.rb
84
+ - lib/stairs/step.rb
85
+ - lib/stairs/steps.rb
86
+ - lib/stairs/steps/s3.rb
87
+ - lib/stairs/steps/secret_token.rb
88
+ - lib/stairs/tasks.rb
89
+ - lib/stairs/version.rb
90
+ - stairs.gemspec
91
+ homepage: http://github.com/patbenatar/stairs
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: A DSL and collection of plugins for easy setup of projects on new development
115
+ environments.
116
+ test_files: []