noveku 0.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ notifications:
8
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ noveku (0.4)
5
+ gomon
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activesupport (3.2.11)
11
+ i18n (~> 0.6)
12
+ multi_json (~> 1.0)
13
+ diff-lcs (1.1.3)
14
+ gomon (0.0.4)
15
+ activesupport
16
+ i18n (0.6.1)
17
+ multi_json (1.5.0)
18
+ rake (10.0.3)
19
+ rspec (2.12.0)
20
+ rspec-core (~> 2.12.0)
21
+ rspec-expectations (~> 2.12.0)
22
+ rspec-mocks (~> 2.12.0)
23
+ rspec-core (2.12.2)
24
+ rspec-expectations (2.12.1)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.12.1)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ noveku!
33
+ rake
34
+ rspec
data/README.md CHANGED
@@ -5,11 +5,7 @@ This gem was inspired by [a collection of thoughtbot aliases](https://github.com
5
5
 
6
6
  ## Prerequisites
7
7
 
8
- This gem depends on no other gems. However :
9
-
10
- * the presence of the command `heroku` (either via the gem, or the toolbelt) is assumed;
11
- * the `hrs` tool assumes there is a heroku git remote named `staging`;
12
- * the `hrp` tool assumes there is a heroku git remove named `production`.
8
+ Ruby 1.9+ only. This gem depends on novelys/gomon. However, the presence of the command `heroku` (either via the gem, or the toolbelt) is assumed
13
9
 
14
10
  ## Installation
15
11
 
@@ -18,10 +14,14 @@ you should install it globally, not via bundler and your project's Gemfile.
18
14
 
19
15
  ## Usage
20
16
 
21
- This gem exposes two executables :
17
+ `noveku ENV commands...`: will execute the given commands for the `ENV` remote.
18
+
19
+ We strongly suggest adding shell aliases for convenience :
22
20
 
23
- * `hrs` (heroku staging) : will execute the given commands for the `staging` remote
24
- * `hrp` (heroku production) : will execute the given commands for the `production` remote
21
+ ```shell
22
+ alias nvp='noveku production'
23
+ alias nvs='noveku staging'
24
+ ```
25
25
 
26
26
  ## Heroku commands
27
27
 
@@ -33,7 +33,7 @@ Supported commands and their equivalent :
33
33
  * `tail`: `heroku logs --tail --remote ENV`
34
34
 
35
35
  When giving a command that is not specifically supported, it will be passed to `heroku` : `heroku ARGS --remote ENV`.
36
- This makes several other commands available, such as `restart`, `releases`, ...
36
+ This makes several other commands available, such as `restart`, `releases`, `ps`, `open`...
37
37
 
38
38
  ## Advanced commands
39
39
 
@@ -41,9 +41,13 @@ This makes several other commands available, such as `restart`, `releases`, ...
41
41
  * `mongolab_dump`: Dumps the mongo database. Look in the config keys of `ENV` to find `MONGOLAB_URI`.
42
42
  * `mongohq_dump`: Dumps the mongo database. Look in the config keys of `ENV` to find `MONGOHQ_URL`.
43
43
 
44
- Those commands puts the dump in the `dump` dir, relatively to where you executed it.
44
+ Those commands put the dump in the `dump` dir, relatively to where you executed it.
45
+
46
+ Since the restoration of the database does not involve any interaction with heroku, it is out of the scope of this gem at the moment. However, this gem depends on novelys/gomon, which includes a class wrapping mongodump/restore, making it very easy to use in a rake task.
47
+
48
+ ## What's next
45
49
 
46
- Since the restoration of the database does not involve any interaction with heroku, it is out of the scope of this gem at the moment. However, it is pretty easy to integrate the commands above and the restoration in a rake task.
50
+ I plan on adding a command allowing you to create a heroku app, setup your addons, update your git config, create a local branch if needed.. all that in one step. We're still thinking about what the command api will look like. This will probably be the last feature before tagging 1.0.0.
47
51
 
48
52
  ## Contributions
49
53
 
@@ -54,6 +58,8 @@ Since the restoration of the database does not involve any interaction with hero
54
58
 
55
59
  ## Changelog
56
60
 
61
+ * `0.5`: Test coverage, check the presence of environment & that it matches a heroku app, that pwd is a heroku app, the presence of mongohq/lab uri.
62
+ * `0.4`: Require `gomon` for mongodump, changed executable names, internal refactoring.
57
63
  * `0.3`: Added `mongodump`, `mongolab_dump`, `mongohq_dump`.
58
64
  * `0.2`: Added `rake` command.
59
65
  * `0.1`: First version. Available commands : `console`, `migrate`, `tail`.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ Bundler::GemHelper.install_tasks
6
+ rescue LoadError
7
+ puts 'although not required, bundler is recommened for running the tests'
8
+ end
9
+
10
+ task default: :spec
11
+
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new do |t|
14
+ t.rspec_opts = ["--color", '--format doc']
15
+ end
data/bin/noveku ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'noveku'
4
+
5
+ Noveku::Core.new(*ARGV).call
data/lib/noveku.rb CHANGED
@@ -1,4 +1,2 @@
1
- require 'noveku/base'
2
- require 'noveku/production'
3
- require 'noveku/staging'
4
1
  require 'noveku/version'
2
+ require 'noveku/core'
@@ -0,0 +1,15 @@
1
+ module Noveku
2
+ module Config
3
+ def config_value_str(key)
4
+ "config:get #{key}"
5
+ end
6
+
7
+ # Returns config value for key
8
+ def config_value_for(key)
9
+ cmd = executable_command config_value_str(key)
10
+ value = `#{cmd}`.strip
11
+ value = nil if value == ''
12
+ value
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Noveku
2
+ module Console
3
+ def console_cmd_str
4
+ 'run console'
5
+ end
6
+
7
+ # Open the console
8
+ def console_cmd
9
+ execute console_cmd_str
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ require 'noveku/config'
2
+ require 'noveku/exceptions'
3
+ require 'noveku/rake'
4
+ require 'noveku/console'
5
+ require 'noveku/migrate'
6
+ require 'noveku/proxy'
7
+ require 'noveku/tail'
8
+ require 'noveku/mongo'
9
+
10
+ module Noveku
11
+ # Common functionnality
12
+ class Core
13
+ include Config
14
+ include Exceptions
15
+ # Aliases
16
+ include Rake
17
+ include Console
18
+ include Migrate
19
+ include Proxy
20
+ include Tail
21
+ # Advanced Features
22
+ include Mongo
23
+
24
+ attr_reader :environment, :command, :arguments
25
+
26
+ # Keep track of the given commands
27
+ def initialize(*arguments)
28
+ @environment = arguments.shift
29
+
30
+ ensure_env
31
+ ensure_heroku_app
32
+
33
+ @command = arguments.shift
34
+ @arguments = arguments
35
+ rescue Exception => e
36
+ handle_exception(e)
37
+ end
38
+
39
+ # Run the commands
40
+ def call
41
+ send "#{@command}_cmd"
42
+ end
43
+
44
+ private
45
+
46
+ # Execute the commands
47
+ def execute(*commands)
48
+ system executable_command(*commands)
49
+ end
50
+
51
+ # Build command to execute
52
+ def executable_command(*commands)
53
+ return nil unless commands
54
+
55
+ # Template proc
56
+ template = ->(command) { "heroku #{command} --remote '#{environment}'" }
57
+
58
+ # Map commands to template & chain
59
+ commands.map(&template).join(' && ')
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,77 @@
1
+ module Noveku
2
+ # Raised if environment is not present
3
+ class NotAValidEnvironment < StandardError; end
4
+
5
+ # Raised if `pwd` is not a git repo or no app was found
6
+ class NoHerokuApp < StandardError; end
7
+
8
+ module Mongo
9
+ # Raised if no mongo uri was found
10
+ class NoUriSupplied < StandardError; end
11
+ end
12
+
13
+ module Exceptions
14
+ private
15
+
16
+ # Check if environment is present
17
+ def ensure_env
18
+ raise NotAValidEnvironment unless @environment
19
+ end
20
+
21
+ # Check if there is a matching heroku app
22
+ def ensure_heroku_app
23
+ # This env is used for testing
24
+ return if environment == 'noveku-safe-env'
25
+
26
+ system "heroku releases --remote '#{environment}' >& /dev/null"
27
+
28
+ raise NoHerokuApp unless $?.exitstatus == 0
29
+ end
30
+
31
+ # Print message, then exits
32
+ def handle_exception(e)
33
+ explain_exception(e)
34
+ exit(1)
35
+ end
36
+
37
+ # Print a message explaining error
38
+ def explain_exception(e)
39
+ case e
40
+ when Noveku::NotAValidEnvironment
41
+ explain_invalid_env
42
+ when Noveku::NoHerokuApp
43
+ explain_no_heroku
44
+ when Noveku::Mongo::NoUriSupplied
45
+ explain_no_uri
46
+ else raise
47
+ end
48
+ end
49
+
50
+ # Print a message explaining the env is not valid
51
+ def explain_invalid_env
52
+ explanation = <<-ENV
53
+ You did not supply a environment to use.
54
+ ENV
55
+
56
+ puts explanation.strip
57
+ end
58
+
59
+ # Print a message explaining there is no herok
60
+ def explain_no_heroku
61
+ explanation = <<-HER
62
+ The current directory doesn't seem to be a heroku app, or the environment given doesn't match a heroku app.
63
+ HER
64
+
65
+ puts explanation.strip
66
+ end
67
+
68
+ # Print a message explaining
69
+ def explain_no_uri
70
+ explanation = <<-URI
71
+ There is no mongodb uri in the config.
72
+ URI
73
+
74
+ puts explanation.strip
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,13 @@
1
+ module Noveku
2
+ module Migrate
3
+ # Migrate args
4
+ def migrate_cmd_args
5
+ ['run rake db:migrate', 'restart']
6
+ end
7
+
8
+ # Open the console
9
+ def migrate_cmd
10
+ execute *migrate_cmd_args
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'gomon/dump'
2
+
3
+ module Noveku
4
+ module Mongo
5
+ # Heroku config keys name
6
+ MONGOLAB_KEY = 'MONGOLAB_URI'
7
+ MONGOHQ_KEY = 'MONGOHQ_URL'
8
+
9
+ # Dump mongolab or mongohq db
10
+ def mongodump_cmd
11
+ uri = config_value_for(MONGOLAB_KEY) || config_value_for(MONGOHQ_KEY)
12
+
13
+ mongo_dump uri
14
+ end
15
+
16
+ # Dump mongolab db
17
+ def mongolab_dump_cmd
18
+ mongo_dump config_value_for(MONGOLAB_KEY)
19
+ end
20
+
21
+ # Dump mongohq db
22
+ def mongohq_dump_cmd
23
+ mongo_dump config_value_for(MONGOHQ_KEY)
24
+ end
25
+
26
+ # Get a dump of the database
27
+ def mongo_dump(uri)
28
+ raise NoUriSupplied unless uri
29
+
30
+ Gomon::Dump.new(uri: uri).call
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ module Noveku
2
+ module Proxy
3
+ # String to execute when proxying commands
4
+ def proxy_cmd_str
5
+ ([@command] + @arguments).join(' ')
6
+ end
7
+
8
+ # If this is a command with no specific support, pass the raw arguments to `heroku` directly
9
+ def method_missing(name, *args, &block)
10
+ if name.to_s.end_with?('_cmd')
11
+ execute proxy_cmd_str
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ # Expose proxying handling
18
+ def respond_to_missing?(name, include_private)
19
+ if name.to_s.end_with?('_cmd')
20
+ true
21
+ else
22
+ super
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module Noveku
2
+ module Rake
3
+ # Rake command string
4
+ def rake_cmd_str
5
+ task = @arguments.join(' ')
6
+
7
+ "run rake #{task}"
8
+ end
9
+
10
+ # Execute a rake task
11
+ def rake_cmd
12
+ execute rake_cmd_str
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Noveku
2
+ module Tail
3
+ # Tail command string
4
+ def tail_cmd_str
5
+ 'logs --tail'
6
+ end
7
+
8
+ # Tail logs
9
+ def tail_cmd
10
+ execute tail_cmd_str
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Noveku
2
- VERSION = '0.3'
2
+ VERSION = '0.5'
3
3
  end
data/noveku.gemspec CHANGED
@@ -13,7 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.rubyforge_project = s.name
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.files = `git ls-files`.split("\n")
16
- s.executables << 'hrp'
17
- s.executables << 'hrs'
16
+ s.executables << 'noveku'
18
17
  s.require_path = 'lib'
18
+ s.add_dependency('gomon')
19
+ s.add_development_dependency('rake')
20
+ s.add_development_dependency('rspec')
19
21
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Config' do
5
+ subject { Noveku::Core.new 'noveku-safe-env' }
6
+
7
+ it 'must have an executable command string' do
8
+ key = (0...4).map{65.+(rand(26)).chr}.join('')
9
+
10
+ expect(subject.config_value_str(key)).to eq "config:get #{key}"
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Console' do
5
+ subject { Noveku::Core.new 'noveku-safe-env', 'console' }
6
+
7
+ it 'must have an executable command string' do
8
+ expect(subject.console_cmd_str).to eq 'run console'
9
+ end
10
+ end
data/spec/core_spec.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Core' do
5
+ context 'environment' do
6
+ it 'absence should raise an exception' do
7
+ expect(-> { Noveku::Core.new }).to raise_error(SystemExit)
8
+ end
9
+ end
10
+
11
+ context 'commands' do
12
+ subject { Noveku::Core.new 'noveku-safe-env', 'rake', 'stats' }
13
+
14
+ it 'environment should be the first command' do
15
+ expect(subject.environment).to eq 'noveku-safe-env'
16
+ end
17
+
18
+ it 'main command should be the second command' do
19
+ expect(subject.command).to eq 'rake'
20
+ end
21
+
22
+ it 'argument should be the remaining' do
23
+ expect(subject.arguments).to eq ['stats']
24
+ end
25
+
26
+ it 'string to execute should contain given command' do
27
+ str = "heroku run rake stats --remote 'noveku-safe-env'"
28
+ expect(subject.send(:executable_command, 'run rake stats')).to eq str
29
+ end
30
+
31
+ it 'string to execute should chain given command' do
32
+ str = "heroku run rake stats --remote 'noveku-safe-env' && heroku releases --remote 'noveku-safe-env'"
33
+ expect(subject.send(:executable_command, 'run rake stats', 'releases')).to eq str
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Migrate' do
5
+ subject { Noveku::Core.new 'noveku-safe-env', 'migrate' }
6
+
7
+ it 'must have a command args' do
8
+ expect(subject.migrate_cmd_args).to eq ['run rake db:migrate', 'restart']
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Mongodump' do
5
+ context 'MongoHQ' do
6
+ subject { Noveku::Core.new 'noveku-safe-env', 'mongohq_dump' }
7
+
8
+ it 'should raise an exception when no uri in the config' do
9
+ expect(-> { subject.mongohq_dump_cmd }).to raise_error Noveku::Mongo::NoUriSupplied
10
+ end
11
+ end
12
+
13
+ context 'MongoLab' do
14
+ subject { Noveku::Core.new 'noveku-safe-env', 'mongolab_dump' }
15
+
16
+ it 'should raise an exception when no uri in the config' do
17
+ expect(-> { subject.mongohq_dump_cmd }).to raise_error Noveku::Mongo::NoUriSupplied
18
+ end
19
+ end
20
+
21
+
22
+ subject { Noveku::Core.new 'noveku-safe-env', 'mongodump' }
23
+
24
+ it 'should raise an exception when no uri in the config' do
25
+ expect(-> { subject.mongodump_cmd }).to raise_error Noveku::Mongo::NoUriSupplied
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Proxy' do
5
+ subject { Noveku::Core.new 'noveku-safe-env', 'ps', 'web' }
6
+
7
+ it 'must have an executable command string' do
8
+ expect(subject.proxy_cmd_str).to eq 'ps web'
9
+ end
10
+
11
+ it 'should be called when missing method ends with _cmd' do
12
+ valid_method_name = "#{(0...8).map{65.+(rand(26)).chr}.join}_cmd"
13
+ expect(subject).to respond_to valid_method_name
14
+ end
15
+ end
data/spec/rake_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Rake' do
5
+ subject { Noveku::Core.new 'noveku-safe-env', 'rake', 'arg1', 'arg2' }
6
+
7
+ it 'must have an executable command string' do
8
+ expect(subject.rake_cmd_str).to eq 'run rake arg1 arg2'
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
data/spec/tail_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'noveku/core'
3
+
4
+ describe 'Tail' do
5
+ subject { Noveku::Core.new 'noveku-safe-env', 'tail' }
6
+
7
+ it 'must have an executable command string' do
8
+ expect(subject.tail_cmd_str).to eq 'logs --tail'
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noveku
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,27 +10,93 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-13 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2013-01-19 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gomon
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rake
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
15
63
  description: A set of heroku aliases meant to speed up heroku interaction when dealing
16
64
  with multilple heroku remotes.
17
65
  email:
18
66
  - contact@novelys.com
19
67
  executables:
20
- - hrp
21
- - hrs
68
+ - noveku
22
69
  extensions: []
23
70
  extra_rdoc_files: []
24
71
  files:
72
+ - .rspec
73
+ - .travis.yml
74
+ - Gemfile
75
+ - Gemfile.lock
25
76
  - README.md
26
- - bin/hrp
27
- - bin/hrs
77
+ - Rakefile
78
+ - bin/noveku
28
79
  - lib/noveku.rb
29
- - lib/noveku/base.rb
30
- - lib/noveku/production.rb
31
- - lib/noveku/staging.rb
80
+ - lib/noveku/config.rb
81
+ - lib/noveku/console.rb
82
+ - lib/noveku/core.rb
83
+ - lib/noveku/exceptions.rb
84
+ - lib/noveku/migrate.rb
85
+ - lib/noveku/mongo.rb
86
+ - lib/noveku/proxy.rb
87
+ - lib/noveku/rake.rb
88
+ - lib/noveku/tail.rb
32
89
  - lib/noveku/version.rb
33
90
  - noveku.gemspec
91
+ - spec/config_spec.rb
92
+ - spec/console_spec.rb
93
+ - spec/core_spec.rb
94
+ - spec/migrate_spec.rb
95
+ - spec/mongo_spec.rb
96
+ - spec/proxy_spec.rb
97
+ - spec/rake_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/tail_spec.rb
34
100
  homepage: http://github.com/novelys/noveku
35
101
  licenses: []
36
102
  post_install_message:
data/bin/hrp DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'noveku'
4
-
5
- production = Noveku::Production.new(ARGV)
6
- production.run
data/bin/hrs DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'noveku'
4
-
5
- staging = Noveku::Staging.new(ARGV)
6
- staging.run
data/lib/noveku/base.rb DELETED
@@ -1,108 +0,0 @@
1
- module Noveku
2
- # Heroku config keys name
3
- MONGOLAB_KEY = 'MONGOLAB_URI'
4
- MONGOHQ_KEY = 'MONGOHQ_URL'
5
-
6
- # This exception will be raised if @environment is not present
7
- class NotAValidEnvironment < StandardError; end
8
-
9
- # Common functionnality
10
- class Base
11
- # Keep track of the given commands
12
- def initialize(commands)
13
- @commands = commands
14
- @command = @commands.first
15
- end
16
-
17
- # Run the commands
18
- def run
19
- raise NotAValidEnvironment unless @environment
20
-
21
- send "#{@command}_cmd"
22
- end
23
-
24
- # Execute a rake task
25
- def rake_cmd
26
- task = @commands[1..-1].join(' ')
27
- system "heroku run rake #{task} --remote #{@environment}"
28
- end
29
-
30
- # Open the console
31
- def console_cmd
32
- system "heroku run console --remote #{@environment}"
33
- end
34
-
35
- # Execute migrations & restart app
36
- def migrate_cmd
37
- system %{
38
- heroku run rake db:migrate --remote #{@environment} &&
39
- heroku restart --remote #{@environment}
40
- }
41
- end
42
-
43
- # Tail logs
44
- def tail_cmd
45
- system "heroku logs --tail --remote #{@environment}"
46
- end
47
-
48
- # Dump mongolab or mongohq db
49
- def mongodump_cmd
50
- uri = config_value_for(MONGOLAB_KEY) || config_value_for(MONGOHQ_KEY)
51
-
52
- mongo_dump(uri)
53
- end
54
-
55
- # Dump mongolab db
56
- def mongolab_dump_cmd
57
- mongo_dump config_value_for(MONGOLAB_KEY)
58
- end
59
-
60
- # Dump mongohq db
61
- def mongohq_dump_cmd
62
- mongo_dump config_value_for(MONGOHQ_KEY)
63
- end
64
-
65
- def method_missing(name, *args, &block)
66
- # If this is a command with no specific support, pass the raw arguments to `heroku` directly
67
- if name.to_s.end_with?('_cmd')
68
- system "heroku #{@commands.join(' ')} --remote #{@environment}"
69
- else
70
- super
71
- end
72
- end
73
-
74
- private
75
-
76
- # Returns config value for key
77
- def config_value_for(key)
78
- uri = `heroku config:get #{key} --remote #{@environment}`.strip
79
- uri = nil if uri == ''
80
- uri
81
- end
82
-
83
- # Returns a hash of data parsed from the mongo uri
84
- def mongo_uri_parse(uri)
85
- matches = uri.match /mongodb:\/\/([^:]*):([^@]*)@([^:]*):(\d*)\/(.*)/i
86
-
87
- {
88
- user: matches[1],
89
- password: matches[2],
90
- host: matches[3],
91
- port: matches[4],
92
- database: matches[5]
93
- }
94
- end
95
-
96
- # Get a dump of the database
97
- def mongo_dump(uri)
98
- if uri
99
- opts = mongo_uri_parse(uri)
100
- puts "Dumping `#{opts[:database]}` from #{opts[:host]}..."
101
- system "mongodump -h #{opts[:host]}:#{opts[:port]} -d #{opts[:database]} -u #{opts[:user]} -p #{opts[:password]}"
102
- puts 'Done.'
103
- else
104
- puts 'No uri.'
105
- end
106
- end
107
- end
108
- end
@@ -1,8 +0,0 @@
1
- module Noveku
2
- class Production < Base
3
- def initialize(commands)
4
- @environment = 'production'
5
- super(commands)
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module Noveku
2
- class Staging < Base
3
- def initialize(commands)
4
- @environment = 'staging'
5
- super(commands)
6
- end
7
- end
8
- end