stairs 0.1.0 → 0.2.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: d1035904a5f2df9f1310a2a7499500e6bb123589
4
- data.tar.gz: b96bd24c537f525276cc2c585a12bc8372175e61
3
+ metadata.gz: f617dda7fd3f43d796cde18e6cd509b7556ea2f4
4
+ data.tar.gz: 8e2926466d8c307a8dbcd9be9a5a320e320495c5
5
5
  SHA512:
6
- metadata.gz: 2c1fe6a87b3af48fb04782a2e773e4fa6284e23141fb34f38dd78e6aebeae835f459d75ad8e6b2f945ee0613701db1345fc83a97d990ee3dc9c3702a50292145
7
- data.tar.gz: 05cdd22e964203a638fad22ba4e757bb479e1b54611aad59162caf8af8bdf2604527d3399bfa492aa8bba5aa0e571102479406698cdd694f9b963a1c7486b3fd
6
+ metadata.gz: eb0910186b1a3886ecff848942bb6c119cc58f7017fc74b0720ccf142aa0495eba3a0ba3461de3d9af65276fc3272da90b6d769067bc299b8525e35efe0ad9e2
7
+ data.tar.gz: fc18be8d140dbd7c1c1b07d3252f3b7a389e0826d855693120b86c6edc30a7fdb424a3fb9ab1f8d449eaa79aa59a5554bbdffc99eb1a2201066c3f1f08081978
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Stairs
2
2
 
3
3
  A DSL and collection of plugins for easy setup of projects on new development
4
- environments.
4
+ environments. Write a script that new devs can run for an interactive setup.
5
+ For environment variables, Stairs supports rbenv-vars, RVM, and dotenv.
5
6
 
6
7
  ## Setup
7
8
 
8
9
  1. Install gem `stairs`
9
10
 
10
- 1. Require tasks in Rakefile
11
+ 1. Require tasks in `Rakefile`
11
12
  ```ruby
12
13
  require "stairs/tasks"
13
14
  ```
@@ -41,7 +42,8 @@ puts "Sweet you're good to go. Just run `rails s` and `sidekiq` to get rolling!"
41
42
 
42
43
  ### Example CLI
43
44
 
44
- Given the above script, the CLI would look like this:
45
+ Given the above script, the CLI might look like this. __Note:__ some of this
46
+ is desired future functionality (bundle/db tasks, spacing, last words).
45
47
 
46
48
  ```
47
49
  $ rake newb
@@ -69,7 +71,7 @@ Run rails s and sidekiq to get rolling!
69
71
  ### Collecting values
70
72
  ```ruby
71
73
  value = provide "Something"
72
- value = provide "Another", required: false
74
+ value = provide "Another", required: false # Not fully implemented
73
75
  provide "More", default: "a-default"
74
76
  ```
75
77
 
@@ -111,11 +113,16 @@ setup :s3
111
113
 
112
114
  ## Plugins for common setups
113
115
 
116
+ ### Built-in
114
117
  * `:secret_token` sets a secure random secret token
118
+
119
+ ### Available as extension gems
115
120
  * `:s3` interactive prompt for setting AWS + S3 bucket access credentials:
116
121
  [patbenatar/stairs-steps-s3][s3]
117
- * `:balanced`: automatically creates a test Marketplace on Balanced:
122
+ * `:balanced` automatically creates a test Marketplace on Balanced:
118
123
  [patbenatar/stairs-steps-balanced][balanced]
124
+ * `:facebook` interactive prompt for setting Facebook app credentials:
125
+ [patbenatar/stairs-steps-facebook][facebook]
119
126
 
120
127
  ### Defining custom plugins
121
128
 
@@ -132,4 +139,5 @@ extension gems for examples.
132
139
  5. Create new Pull Request
133
140
 
134
141
  [s3]: http://github.com/patbenatar/stairs-steps-s3
135
- [balanced]: http://github.com/patbenatar/stairs-steps-balanced
142
+ [balanced]: http://github.com/patbenatar/stairs-steps-balanced
143
+ [facebook]: http://github.com/patbenatar/stairs-steps-facebook
@@ -0,0 +1,5 @@
1
+ module Stairs
2
+ class Configuration
3
+ attr_accessor :env_adapter
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ module Stairs
2
+ module EnvAdapters
3
+ class Dotenv
4
+ def self.present?
5
+ defined? ::Dotenv
6
+ end
7
+
8
+ def set(name, value)
9
+ Util::FileUtils.replace_or_append(
10
+ Regexp.new("^#{name}=(.*)$"),
11
+ "#{name}=#{value}",
12
+ ".env",
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Stairs
2
+ module EnvAdapters
3
+ class Rbenv
4
+ def self.present?
5
+ `which rbenv-vars`
6
+ $?.success?
7
+ end
8
+
9
+ def set(name, value)
10
+ Util::FileUtils.replace_or_append(
11
+ Regexp.new("^#{name}=(.*)$"),
12
+ "#{name}=#{value}",
13
+ ".rbenv-vars",
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Stairs
2
+ module EnvAdapters
3
+ class RVM
4
+ def self.present?
5
+ `which rvm`
6
+ $?.success?
7
+ end
8
+
9
+ def set(name, value)
10
+ Util::FileUtils.replace_or_append(
11
+ Regexp.new("^export #{name}=(.*)$"),
12
+ "export #{name}=#{value}",
13
+ ".rvmrc",
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module Stairs
2
+ module EnvAdapters
3
+ autoload :Rbenv, "stairs/env_adapters/rbenv"
4
+ autoload :RVM, "stairs/env_adapters/rvm"
5
+ autoload :Dotenv, "stairs/env_adapters/dotenv"
6
+
7
+ ADAPTERS = {
8
+ rbenv: Rbenv,
9
+ rvm: RVM,
10
+ dotenv: Dotenv,
11
+ }
12
+
13
+ def self.recommended_adapter
14
+ ADAPTERS.values.find { |a| a.present? }
15
+ end
16
+
17
+ def self.name_for_adapter_class(adapter)
18
+ ADAPTERS.find { |_n,a| a == adapter }.first
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module Stairs
2
+ class InteractiveConfiguration < Stairs::Step
3
+ title "Configuration"
4
+ description "Interactive prompt for configuring Stairs"
5
+
6
+ def run!
7
+ adapter_class = Stairs::EnvAdapters.recommended_adapter
8
+ adapter_name = Stairs::EnvAdapters.name_for_adapter_class(adapter_class)
9
+
10
+ choice "Looks like you're using #{adapter_name} to manage environment variables. Is this correct?" do |yes|
11
+ if yes
12
+ Stairs.configuration.env_adapter = adapter_class.new
13
+ else
14
+ choice "Which would you prefer?", Stairs::EnvAdapters::ADAPTERS.map { |n,_a| n.to_s } do |name|
15
+ adapter_class = Stairs::EnvAdapters::ADAPTERS[name.to_sym]
16
+ Stairs.configuration.env_adapter = adapter_class.new
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/stairs/step.rb CHANGED
@@ -50,32 +50,17 @@ module Stairs
50
50
 
51
51
  # Set or update env var in .rbenv-vars
52
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"
53
+ Stairs.configuration.env_adapter.set name, value
66
54
  end
67
55
 
68
56
  # Replace contents of file
69
57
  def write(string, filename)
70
- File.truncate filename, 0 if File.exists? filename
71
- write_line string, filename
58
+ Util::FileUtils.write(string, filename)
72
59
  end
73
60
 
74
61
  # Append line to file
75
62
  def write_line(string, filename)
76
- File.open filename, "a" do |file|
77
- file.puts string
78
- end
63
+ Util::FileUtils.write_line(string, filename)
79
64
  end
80
65
 
81
66
  # Embed a step where step_name is a symbol that can be resolved to a class
data/lib/stairs/tasks.rb CHANGED
@@ -7,6 +7,7 @@ module Stairs
7
7
  def install!
8
8
  desc "Setup the project"
9
9
  task :newb do
10
+ Stairs::InteractiveConfiguration.new.run!
10
11
  Stairs::Script.new("setup.rb").run!
11
12
  end
12
13
  end
@@ -0,0 +1,31 @@
1
+ module Stairs
2
+ module Util
3
+ module FileUtils
4
+ class << self
5
+ def replace_or_append(pattern, string, filename)
6
+ if File.exists? filename
7
+ contents = File.read filename
8
+ if contents.index pattern
9
+ contents.sub! pattern, string
10
+ write contents, filename
11
+ return
12
+ end
13
+ end
14
+
15
+ write_line string, filename
16
+ end
17
+
18
+ def write_line(string, filename)
19
+ File.open filename, "a" do |file|
20
+ file.puts string
21
+ end
22
+ end
23
+
24
+ def write(string, filename)
25
+ File.truncate filename, 0 if File.exists? filename
26
+ write_line string, filename
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Stairs
2
+ module Util
3
+ autoload :FileUtils, "stairs/util/file_utils"
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Stairs
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/stairs.rb CHANGED
@@ -5,4 +5,18 @@ module Stairs
5
5
  autoload :Step, "stairs/step"
6
6
  autoload :Script, "stairs/script"
7
7
  autoload :Steps, "stairs/steps"
8
+ autoload :EnvAdapters, "stairs/env_adapters"
9
+ autoload :Configuration, "stairs/configuration"
10
+ autoload :InteractiveConfiguration, "stairs/interactive_configuration"
11
+ autoload :Util, "stairs/util"
12
+
13
+ class << self
14
+ def configure
15
+ yield(configuration)
16
+ end
17
+
18
+ def configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+ end
8
22
  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.1.0
4
+ version: 0.2.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-28 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,11 +80,19 @@ files:
80
80
  - README.md
81
81
  - Rakefile
82
82
  - lib/stairs.rb
83
+ - lib/stairs/configuration.rb
84
+ - lib/stairs/env_adapters.rb
85
+ - lib/stairs/env_adapters/dotenv.rb
86
+ - lib/stairs/env_adapters/rbenv.rb
87
+ - lib/stairs/env_adapters/rvm.rb
88
+ - lib/stairs/interactive_configuration.rb
83
89
  - lib/stairs/script.rb
84
90
  - lib/stairs/step.rb
85
91
  - lib/stairs/steps.rb
86
92
  - lib/stairs/steps/secret_token.rb
87
93
  - lib/stairs/tasks.rb
94
+ - lib/stairs/util.rb
95
+ - lib/stairs/util/file_utils.rb
88
96
  - lib/stairs/version.rb
89
97
  - stairs.gemspec
90
98
  homepage: http://github.com/patbenatar/stairs