tol 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-version
7
+ .ruby-gemset
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tol.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex Tandrau
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,34 @@
1
+ # TOL - Speeding up routine tasks
2
+
3
+ A collection of tools used at Take Off Labs for Rails development
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tol'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tol
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ Take Off Labs :: A collection of useful tools for Rails development
23
+
24
+ tol db # Copies the latest version of the database from Heroku to the local development system.
25
+ tol help # Displays this help message.
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/tol ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tol'
4
+ Tol::CLI.new.run
data/dev-notes ADDED
@@ -0,0 +1,20 @@
1
+ # To install on a local system, using bundler:
2
+
3
+ 1. In gem directory
4
+ rake install
5
+ gem server
6
+
7
+ 2. In application directory
8
+ Add to Gemfile, source "source 'http://localhost:8808'"
9
+ Add to Gemfile, gem "tol"
10
+ bundle install
11
+
12
+ # To install on local system, without bundler
13
+ gem install --local /Users/atandrau/work/tol/pkg/tol-0.0.1.gem
14
+
15
+ # Other useful links:
16
+
17
+ 1. https://github.com/geemus/formatador -> formats output
18
+ 2. https://github.com/paul/progress_bar -> progress bar in CLI
19
+ 3. https://github.com/JEG2/highline -> Ask questions to CLI
20
+ 4. http://www.awesomecommandlineapps.com/gems.html -> collection of gems
data/lib/tol/cli.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'tol/database'
2
+
3
+ module Tol
4
+ class CLI
5
+ require 'rainbow'
6
+
7
+ def run
8
+ if ARGV.length == 0
9
+ help
10
+ else
11
+ case ARGV.first
12
+ when "db"
13
+ Tol::Database.new.run
14
+ else
15
+ help
16
+ end
17
+ end
18
+ end
19
+
20
+ def help
21
+ puts " #{"Take Off Labs".foreground(:green).underline} :: " +
22
+ "#{"A collection of useful tools for Rails development".underline}\n\n"
23
+
24
+ database_help
25
+ help_help
26
+ end
27
+
28
+ def database_help
29
+ puts " #{"tol db".foreground(:red)} \# Copies the latest version of the database from Heroku to the local development system."
30
+ end
31
+
32
+ def help_help
33
+ puts " #{"tol help".foreground(:red)} \# Displays this help message."
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,79 @@
1
+ require 'tol/heroku'
2
+ require 'tol/rails_app'
3
+
4
+ module Tol
5
+ class Database
6
+ require 'rainbow'
7
+ require 'highline/import'
8
+
9
+ def run
10
+ puts "Identifying Heroku application"
11
+ apps = Tol::Heroku.new.list_of_applications
12
+
13
+ if apps.length == 0
14
+ puts "No Heroku apps found".foreground(:red)
15
+ elsif apps.length == 1
16
+ download(apps[0])
17
+ else
18
+ puts "Multiple Heroku apps found".foreground(:green)
19
+
20
+ choose do |menu|
21
+ menu.prompt = "Which database should I download?"
22
+ apps.each do |app|
23
+ menu.choice app do
24
+ download(app)
25
+ end
26
+ end
27
+
28
+ menu.choice "None"
29
+ end
30
+ end
31
+ end
32
+
33
+ def download(heroku_app)
34
+ puts "Downloading database for #{heroku_app.underline}".foreground(:green)
35
+
36
+ puts "1. Detecting local database settings.".foreground(:yellow)
37
+ @settings = Tol::RailsApp.new.database_settings["development"]
38
+
39
+ puts "2. Capturing database on Heroku. Please wait.".foreground(:yellow)
40
+ db = `heroku pgbackups:capture --app #{heroku_app} --expire`
41
+
42
+ puts "3. Downloading. Please wait.".foreground(:yellow)
43
+ url = `heroku pgbackups:url --app #{heroku_app}`
44
+ download = `curl -o /tmp/#{heroku_app}.dump '#{url}' > /dev/null 2>&1`
45
+
46
+ puts "4. Importing Database.".foreground(:yellow)
47
+ puts "-> drop old database"
48
+ dropdb = "dropdb"
49
+ dropdb += " -h #{@settings['host']}" if @settings["host"]
50
+ dropdb += " -U #{@settings['user']}" if @settings["user"]
51
+ dropdb += " -P #{@settings['password']}" if @settings["password"]
52
+ dropdb += " #{@settings['database']}"
53
+ drop = `#{dropdb}`
54
+
55
+ puts "-> recreate old database"
56
+ createdb = "createdb"
57
+ createdb += " -h #{@settings['host']}" if @settings["host"]
58
+ createdb += " -U #{@settings['user']}" if @settings["user"]
59
+ createdb += " -P #{@settings['password']}" if @settings["password"]
60
+ createdb += " #{@settings['database']}"
61
+ create = `#{createdb}`
62
+
63
+ puts "-> restore from file"
64
+ restore_command = "pg_restore --verbose --clean --no-acl --no-owner"
65
+ restore_command += " -d #{@settings['database']}"
66
+ restore_command += " -h #{@settings['host']}" if @settings["host"]
67
+ restore_command += " -U #{@settings['user']}" if @settings["user"]
68
+ restore_command += " -P #{@settings['password']}" if @settings["password"]
69
+ restore_command += " /tmp/#{heroku_app}.dump > /dev/null 2>&1"
70
+ restore = `#{restore_command}`
71
+
72
+ puts "5. Cleaning up.".foreground(:yellow)
73
+ clean_up = `rm /tmp/#{heroku_app}.dump`
74
+
75
+ puts "DONE".foreground(:green)
76
+ end
77
+
78
+ end
79
+ end
data/lib/tol/heroku.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Tol
2
+ class Heroku
3
+ def list_of_applications
4
+ git_config = File.read(".git/config")
5
+ git_config.scan(/heroku\..*:(.*)\.git/i).map do |result|
6
+ result[0]
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Tol
2
+ class RailsApp
3
+ def database_settings
4
+ require 'yaml'
5
+ settings = YAML.load_file("config/database.yml")
6
+ settings
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Tol
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tol.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "tol/version"
2
+ require "tol/cli"
3
+
4
+ module Tol
5
+
6
+ end
data/tol.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/tol/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alex Tandrau"]
6
+ gem.email = ["alex@takeofflabs.com"]
7
+ gem.description = %q{A collection of tools used at Take Off Labs for Rails development}
8
+ gem.summary = %q{Heroku interactions, etc.}
9
+ gem.homepage = "http://www.takeofflabs.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "tol"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Tol::VERSION
17
+
18
+ # Development tools
19
+ gem.add_development_dependency "pry"
20
+
21
+ # Runtime gems
22
+ gem.add_dependency "rainbow" # https://github.com/sickill/rainbow
23
+ gem.add_dependency "highline"
24
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Tandrau
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rainbow
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: highline
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: A collection of tools used at Take Off Labs for Rails development
63
+ email:
64
+ - alex@takeofflabs.com
65
+ executables:
66
+ - tol
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - bin/tol
76
+ - dev-notes
77
+ - lib/tol.rb
78
+ - lib/tol/cli.rb
79
+ - lib/tol/database.rb
80
+ - lib/tol/heroku.rb
81
+ - lib/tol/rails_app.rb
82
+ - lib/tol/version.rb
83
+ - tol.gemspec
84
+ homepage: http://www.takeofflabs.com
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Heroku interactions, etc.
108
+ test_files: []