shoestring 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08da0f8b75784fc64d88785f2c2e35d5cabc77f5
4
+ data.tar.gz: b1481151bb438ed3a6624f2362da0ce3536f1140
5
+ SHA512:
6
+ metadata.gz: 4b28d87c4f9e6639c2b1d111d317990eb543f648d7ef761d163853869ebb11ecdf8f6e78874aaf5e2d564c115042d3f24bb4dabbc83017d29f52ed935d6899a3
7
+ data.tar.gz: 33d615b81703b101e68e99386db88688447b3fe327e1e7ac495f3e41cb65fb40b4c994b0d27d712a643041c8da4da32489b32056916cf957fabb7a6dff4ef536
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 shoestring.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Caleb Woods
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,35 @@
1
+ # Shoestring
2
+
3
+ Automate setting up Rails development environment including external dependencies.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'shoestring'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install shoestring
18
+
19
+ ## Usage
20
+
21
+ TODO: Add examples
22
+ TODO: Add generator to get started
23
+
24
+ ## TODO
25
+
26
+ * Link specific versions with Homebrew
27
+ * Check for specific DB versions
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ module Shoestring
2
+ class Bundler < Base
3
+
4
+ def check
5
+ install_bundler
6
+ install_gems
7
+ end
8
+
9
+ private
10
+
11
+ def install_bundler
12
+ Shoestring::Generic.check('Bundler') do
13
+ unless system('bundle --version 2>&1')
14
+ puts "Unable to find bundler. Installing..."
15
+ system('gem install bundler')
16
+ end
17
+ true
18
+ end
19
+ end
20
+
21
+ def install_gems
22
+ Shoestring::Cache.check(:bundle) do |old_version|
23
+ version = File.read('Gemfile') + File.read('Gemfile.lock')
24
+ if old_version != version
25
+ system('bundle install --quiet') || abort('Failed to bundle install')
26
+ end
27
+ version
28
+ end
29
+ puts "Bundle Install: check!"
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Shoestring
2
+ class Cache < Base
3
+ attr_reader :key, :block
4
+
5
+ def initialize(key, &block)
6
+ @key = key
7
+ @block = block
8
+ end
9
+
10
+ def check
11
+ version = block.call(old_version)
12
+ File.open(cache_file, 'w') { |f| f.puts(version || 'cached') }
13
+ end
14
+
15
+ private
16
+ def cache_file
17
+ "tmp/.#{key}"
18
+ end
19
+
20
+ def old_version
21
+ File.exists?(cache_file) ? File.read(cache_file) : nil
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Shoestring
2
+ class CopyConfigFile < Base
3
+ attr_reader :name, :source_file, :destination_file
4
+
5
+ def initialize(name, source_file, destination_file)
6
+ @name = name
7
+ @source_file = source_file
8
+ @destination_file = destination_file
9
+ end
10
+
11
+ def check
12
+ unless File.exists?(destination_file)
13
+ FileUtils.cp source_file, destination_file
14
+ end
15
+ puts "#{name}: check!"
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Shoestring
2
+ class Generic < Base
3
+ attr_reader :name, :message, :block
4
+
5
+ def initialize(name, message="Unable to check #{name}", &block)
6
+ @name = name
7
+ @message = message
8
+ @block = block
9
+ end
10
+
11
+ def check
12
+ block.call || abort(message)
13
+ puts "#{name}: check!"
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ module Shoestring
2
+ class Homebrew < Base
3
+ attr_reader :name, :url, :brew_cmd, :block
4
+
5
+ def initialize(name, url, brew_cmd, &block)
6
+ @name = name
7
+ @url = url
8
+ @brew_cmd = brew_cmd
9
+ @block = block
10
+ end
11
+
12
+ def check
13
+ if block.call
14
+ puts "#{name}: check!"
15
+ else
16
+ puts "You need to setup #{name} #{url}"
17
+
18
+ homebrew_installed = %x(brew -v)
19
+ if homebrew_installed
20
+ install_with_homebrew
21
+ else
22
+ install_homebrew
23
+ install_with_homebrew
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+ def install_homebrew
30
+ puts "Homebrew is not installed. Automatically install (y/n)"
31
+ if STDIN.gets.strip == 'y'
32
+ system('ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"') || abort("Could not install homebrew'. Please try manually http://mxcl.github.io/homebrew/")
33
+ else
34
+ abort_message
35
+ end
36
+ end
37
+
38
+ def install_with_homebrew
39
+ puts "Automatically install using homebrew (y/n)"
40
+ if STDIN.gets.strip == 'y'
41
+ system("brew install #{brew_cmd}") || abort("Could not run 'brew install #{brew_cmd}'. Please try manually")
42
+ else
43
+ abort_message
44
+ end
45
+ end
46
+
47
+ def abort_message
48
+ abort "Install #{name} and rerun"
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,59 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+
4
+ module Shoestring
5
+ class Migration < Base
6
+
7
+ def check
8
+ Shoestring::Generic.check('Database Migrations') do
9
+ status = db_status
10
+ if $?.success?
11
+ check_schema
12
+ true
13
+ else
14
+ setup_database(status)
15
+ end
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def check_schema
22
+ Shoestring::Cache.check(:schema) do |old_version|
23
+ version = File.readlines("db/schema.rb").find { |line| line.include?("define(:version") }
24
+ if old_version != version
25
+ system("bundle exec rake db:migrate") || abort("bundle exec rake db:migrate failed")
26
+ end
27
+ version
28
+ end
29
+ end
30
+
31
+ def setup_database(status)
32
+ if status =~ /role.* does not exist/
33
+ abort "Trouble connecting to database using the user #{db_config['username']}."
34
+ elsif status =~ /database.* does not exist/
35
+ puts "Unable to find the database #{db_config['database']}. Creating it now..."
36
+ system("bundle exec rake db:setup") || abort("bundle exec rake db:setup failed")
37
+ elsif status =~ /relation \"schema_migrations\" does not exist/
38
+ puts "No migrations table. Creating it now..."
39
+ system("bundle exec rake db:setup") || abort("bundle exec rake db:setup failed")
40
+ else
41
+ abort "Error determining the migration status: #{status}"
42
+ end
43
+ end
44
+
45
+ def db_config
46
+ @db_config ||= YAML.load(ERB.new(IO.read('./config/database.yml')).result)['development']
47
+ end
48
+
49
+ def db_status
50
+ if db_config['adapter'] == 'postgresql'
51
+ ENV['PGPASSWORD'] = db_config['password']
52
+ %x(psql -d #{db_config['database']} -U #{db_config['username']} -c "SELECT * from schema_migrations" 2>&1)
53
+ else
54
+ abort("#{db_config['adapter']} is not a support adapter")
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ module Shoestring
2
+ class Postgres < Base
3
+ attr_reader :postgres_interactive
4
+
5
+ def initialize(postgres_interactive = 'psql')
6
+ @postgres_interactive = postgres_interactive
7
+ end
8
+
9
+ def check
10
+ Shoestring::Generic.check('Postgres', install_help) do
11
+ if system("which #{postgres_interactive} >/dev/null")
12
+ true
13
+ else
14
+ puts "Postgres interactive command (#{postgres_interactive}) not found."
15
+ false
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def install_help
23
+ "You need to set up postgres.\nFor development it's recommended to use Postgres.app http://postgresapp.com/"
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module Shoestring
2
+ class PowDns < Base
3
+ attr_reader :port
4
+
5
+ def initialize(port = 3000)
6
+ @port = port
7
+ end
8
+
9
+ def check
10
+ Shoestring::Generic.check('Pow DNS') do
11
+ # config port for forman if installed
12
+ %x(if [ -f Procfile ]; then echo "port: #{port}" > .foreman; fi)
13
+
14
+ # Set up DNS through Pow
15
+ %x(if [ -d ~/.pow ]
16
+ then
17
+ echo #{port} > ~/.pow/`basename $PWD`
18
+ else
19
+ echo "Pow is not set up but the team uses it for this project. Setup: http://goo.gl/RaDPO"
20
+ fi)
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module Shoestring
2
+ class Rbenv < Base
3
+
4
+ def check
5
+ check_for_rvm
6
+ Shoestring::Homebrew.check('rbenv', 'https://github.com/sstephenson/rbenv', 'rbenv') { %x(rbenv --version 2>&1); $?.success? }
7
+ Shoestring::Homebrew.check('ruby-build', 'https://github.com/sstephenson/ruby-build', 'ruby-build') { %x(rbenv --version 2>&1); $?.success? }
8
+ Shoestring::Generic.check('rbenv configured') do
9
+ unless system('echo $PATH | grep "$(rbenv root)/shims" > /dev/null')
10
+ puts "rbenv not initialize in .bash_profile."
11
+ puts "Add the following line to your .bash_profile or equivalent and rerun."
12
+ abort('if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi')
13
+ end
14
+ true
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def check_for_rvm
21
+ if system('which rvm')
22
+ abort('RVM is installed and must be removed to use rbenv. See RVM website for details: http://rvm.io/rvm/cli')
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ module Shoestring
2
+ class Server
3
+
4
+ def self.start(command = 'bundle exec rails s')
5
+ puts "\nShoestrings tied!\n\nStarting app server..."
6
+ system %(#{command})
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Shoestring
2
+ VERSION = "0.0.3"
3
+ end
data/lib/shoestring.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "shoestring/version"
2
+
3
+ module Shoestring
4
+ class Base
5
+
6
+ def self.check(*args, &block)
7
+ self.new(*args, &block).check
8
+ end
9
+
10
+ end
11
+ end
12
+
13
+ require "shoestring/bundler"
14
+ require "shoestring/cache"
15
+ require "shoestring/copy_config_file"
16
+ require "shoestring/generic"
17
+ require "shoestring/homebrew"
18
+ require "shoestring/migration"
19
+ require "shoestring/postgres"
20
+ require "shoestring/pow_dns"
21
+ require "shoestring/rbenv"
22
+ require "shoestring/server"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shoestring/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shoestring"
8
+ spec.version = Shoestring::VERSION
9
+ spec.authors = ["Caleb Woods"]
10
+ spec.email = ["calebawoods@gmail.com"]
11
+ spec.description = %q{Helps you manage development dependencies for your Rails app}
12
+ spec.summary = %q{See Github page for examples}
13
+ spec.homepage = "http://rolemodelsoftware.com"
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
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoestring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Woods
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-06 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
+ description: Helps you manage development dependencies for your Rails app
42
+ email:
43
+ - calebawoods@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/shoestring.rb
54
+ - lib/shoestring/bundler.rb
55
+ - lib/shoestring/cache.rb
56
+ - lib/shoestring/copy_config_file.rb
57
+ - lib/shoestring/generic.rb
58
+ - lib/shoestring/homebrew.rb
59
+ - lib/shoestring/migration.rb
60
+ - lib/shoestring/postgres.rb
61
+ - lib/shoestring/pow_dns.rb
62
+ - lib/shoestring/rbenv.rb
63
+ - lib/shoestring/server.rb
64
+ - lib/shoestring/version.rb
65
+ - shoestring.gemspec
66
+ homepage: http://rolemodelsoftware.com
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.0.2
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: See Github page for examples
90
+ test_files: []
91
+ has_rdoc: