commands 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rails"
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jbuilder (0.9.1)
5
+ activesupport (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionpack (3.2.8)
11
+ activemodel (= 3.2.8)
12
+ activesupport (= 3.2.8)
13
+ builder (~> 3.0.0)
14
+ erubis (~> 2.7.0)
15
+ journey (~> 1.0.4)
16
+ rack (~> 1.4.0)
17
+ rack-cache (~> 1.2)
18
+ rack-test (~> 0.6.1)
19
+ sprockets (~> 2.1.3)
20
+ activemodel (3.2.8)
21
+ activesupport (= 3.2.8)
22
+ builder (~> 3.0.0)
23
+ activesupport (3.2.8)
24
+ i18n (~> 0.6)
25
+ multi_json (~> 1.0)
26
+ builder (3.0.0)
27
+ erubis (2.7.0)
28
+ hike (1.2.1)
29
+ i18n (0.6.1)
30
+ journey (1.0.4)
31
+ multi_json (1.3.6)
32
+ rack (1.4.1)
33
+ rack-cache (1.2)
34
+ rack (>= 0.4)
35
+ rack-test (0.6.1)
36
+ rack (>= 1.0)
37
+ rake (0.9.2.2)
38
+ sprockets (2.1.3)
39
+ hike (~> 1.2)
40
+ rack (~> 1.0)
41
+ tilt (~> 1.1, != 1.3.0)
42
+ tilt (1.3.3)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ actionpack
49
+ jbuilder!
50
+ rake
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 David Heinemeier Hansson, 37signals
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ Commands
2
+ ========
3
+
4
+ Let you run Rake and Rails commands during a console session. This side-steps the need to load the entire environment over and over again when you run these commands from the shell. This constant reloading of the environment is what causes slow boot time on big applications. Think of this like a baby Zeus or the Turbolinks of commands.
5
+
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'commands'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Usage
19
+ -----
20
+
21
+ When your console boots, it'll automatically have a `commands` object instantiated (aliased to `c`). The following methods are delegated to this object: rake, test, generate, destroy, update. It's used like this:
22
+
23
+ > generate "scaffold post title:string"
24
+ > rake "db:migrate"
25
+ > test "models/person"
26
+
27
+
28
+ Work needed
29
+ -----------
30
+
31
+ 1. The test runner needs to run in the same process, not use Rake (as it shells out). So the test class needs to be instantiated directly and run under the test environment.
32
+ 1. Generating models seem to be bust for some reason.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rake/testtask'
3
+
4
+ Bundler.require
5
+
6
+ Rake::TestTask.new do |test|
7
+ test.test_files = FileList["test/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/commands.gemspec ADDED
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'commands'
3
+ s.version = '0.0.1'
4
+ s.author = 'David Heinemeier Hansson'
5
+ s.email = 'david@37signals.com'
6
+ s.summary = 'Run Rake/Rails commands through the console'
7
+
8
+ s.add_dependency 'rails', '>= 3.0.0'
9
+
10
+ s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
11
+ end
data/lib/commands.rb ADDED
@@ -0,0 +1,78 @@
1
+ require 'rake'
2
+
3
+ class Commands
4
+ module ConsoleMethods
5
+ def commands
6
+ @commands ||= Commands.new
7
+ end
8
+
9
+ alias_method :c, :commands
10
+
11
+ delegate :rake, :test, :generate, :destroy, :update, to: :commands
12
+ end
13
+
14
+ include Rake::DSL
15
+
16
+ def initialize
17
+ load Rails.root.join('Rakefile')
18
+ end
19
+
20
+ def rake(task, *args)
21
+ ActiveRecord::Base.logger.silence do
22
+ Rake::Task[task].invoke(*args)
23
+
24
+ # Rake by default only allows tasks to be run once per session
25
+ Rake.application.tasks.each(&:reenable)
26
+ end
27
+ nil
28
+ end
29
+
30
+ # FIXME: Turn this into calls directly to the test classes, so we don't have to load environment again.
31
+ # Also need to toggle the environment to test and back to dev after running.
32
+ def test(what = nil)
33
+ ActiveRecord::Base.logger.silence do
34
+ case what
35
+ when NilClass, :all
36
+ rake "test:units"
37
+ when String
38
+ ENV['TEST'] = "test/#{what}_test.rb"
39
+ rake "test:single"
40
+ ENV['TEST'] = nil
41
+ end
42
+ end
43
+ nil
44
+ rescue SystemExit
45
+ nil
46
+ end
47
+
48
+ def generate(argv = nil)
49
+ generator :generate, argv
50
+ end
51
+
52
+ def update(argv = nil)
53
+ generator :update, argv
54
+ end
55
+
56
+ def destroy(argv = nil)
57
+ generator :destroy, argv
58
+ end
59
+
60
+
61
+ private
62
+ def generator(name, argv = nil)
63
+ if argv.nil?
64
+ # FIXME: I don't know why we can't just catch SystemExit here, then we wouldn't need this if block
65
+ require 'rails/generators'
66
+ Rails::Generators.help name
67
+ else
68
+ ARGV.replace argv.nil? ? [nil] : argv.split(" ")
69
+ load "rails/commands/#{name}.rb"
70
+ ARGV.replace [nil]
71
+ end
72
+
73
+ nil
74
+ end
75
+ end
76
+
77
+ require 'rails/console/app'
78
+ Rails::ConsoleMethods.send :include, Commands::ConsoleMethods
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'active_support/test_case'
3
+
4
+ require 'commands'
5
+
6
+ class CommandsTest < ActiveSupport::TestCase
7
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commands
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Heinemeier Hansson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ description:
31
+ email: david@37signals.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ./commands.gemspec
37
+ - ./Gemfile
38
+ - ./Gemfile.lock
39
+ - ./lib/commands.rb
40
+ - ./MIT-LICENSE
41
+ - ./Rakefile
42
+ - ./README.md
43
+ - ./test/commands_test.rb
44
+ homepage:
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.23
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Run Rake/Rails commands through the console
68
+ test_files: []