igem 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec"
10
+ gem "bundler"
11
+ gem "jeweler"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.4)
5
+ git (1.2.5)
6
+ jeweler (1.8.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.7)
12
+ rake (10.0.4)
13
+ rdoc (4.0.1)
14
+ json (~> 1.4)
15
+ rspec (2.13.0)
16
+ rspec-core (~> 2.13.0)
17
+ rspec-expectations (~> 2.13.0)
18
+ rspec-mocks (~> 2.13.0)
19
+ rspec-core (2.13.1)
20
+ rspec-expectations (2.13.0)
21
+ diff-lcs (>= 1.1.3, < 2.0)
22
+ rspec-mocks (2.13.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler
29
+ jeweler
30
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Bernát Kalló
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = igem
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to igem
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Bernát Kalló. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "igem"
18
+ gem.homepage = "http://github.com/cie/igem"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Load gem commands from the Rails command line with forking}
21
+ gem.description = %Q{With this gem you can load gem commands from the command line with forking, or start Rails subcommands without re-loading the whole rails environment. This can help you speed up the Rails development.}
22
+ gem.email = "kallo.bernat@gmail.com"
23
+ gem.authors = ["Bernát Kalló"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "igem #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/igem.rb ADDED
@@ -0,0 +1,129 @@
1
+ =begin
2
+
3
+ IGem - run gem executables with forking, thus save the loading time. Can be used to speed up Rails generate, Rails server startup or Rake from minutes to seconds.
4
+
5
+ Usage:
6
+ $ rails console
7
+ >> igem "script/something.rb", "argument1 argument2"
8
+ or
9
+ >> igem "rake db:migrate"
10
+ >> igem "rails server", wait: false
11
+ >> igem "rake -T", fork: false
12
+ >> Rails.server
13
+
14
+ You can use a simpler syntax:
15
+
16
+ IGem.rake "db:migrate"
17
+
18
+ You may not be able to change the Rails environment this way because bundler will not load gems from other envs
19
+
20
+
21
+ =end
22
+ module IGem
23
+
24
+ class << self
25
+ def method_missing method_name, cmdline, opts={}
26
+ run "#{method_name} #{cmdline}", opts
27
+ end
28
+
29
+ # Runs the specified command line with forking and loading the gem
30
+ # executable or ruby file.
31
+ #
32
+ # @param cmdline The command line with the executable as the first word. The
33
+ # executable can be a ruby file, a gem executable or a gem name and a gem
34
+ # executable like this: <tt>"rspec-core#rspec"</tt>
35
+ #
36
+ # @param opts a hash containing the options. The following options are
37
+ # available.
38
+ # fork: true to fork the process or just run in this one (! rails generate and some others will stop the process after running)
39
+ # wait: true if fork is true, wait for the forked process with Process.wait
40
+ # reload: true call reload! if it exists
41
+ # env: {} update the environment with these values
42
+ #
43
+ def run cmdline, opts={}
44
+ opts = {
45
+ :fork=>Process.respond_to?(:fork),
46
+ :wait=>true,
47
+ :env=>{},
48
+ :reload=>true
49
+ }.merge(opts)
50
+
51
+ # split cmdline
52
+ cmd, *args = cmdline.scan(/(?:[^"\s]+|"[^"]+")+/).map{|s|s.chars.grep(/[^"]/).join}
53
+
54
+ # find executable
55
+ case cmd
56
+ when /\//
57
+ # for example scripts/something.rb
58
+ executable = cmd
59
+ when /#/
60
+ gem, cmd = *cmd.split("#")
61
+
62
+ # for example rspec-core#rspec
63
+ executable = Gem.bin_path(gem, cmd)
64
+ else
65
+ # for example rspec
66
+ executable = Gem.bin_path(nil, cmd)
67
+ end
68
+
69
+
70
+ # reload
71
+ if opts[:reload]
72
+ reload! if respond_to? :reload!
73
+ end
74
+
75
+
76
+ # if fork is requested
77
+ if opts[:fork]
78
+ fork do
79
+ ENV.update opts[:env]
80
+ ARGV.replace args
81
+ load executable
82
+ end
83
+
84
+ # wait if requested
85
+ Process.wait if opts[:wait]
86
+ else
87
+ # run without forking
88
+
89
+ ENV.update opts[:env]
90
+ ARGV.replace args
91
+ load executable
92
+ end
93
+
94
+ if defined? ActiveRecord
95
+ ActiveRecord::Base.connection.execute("") rescue ActiveRecord::Base.connection.reconnect!
96
+ end
97
+ nil
98
+ end
99
+ end
100
+ end
101
+
102
+ if defined? Rake
103
+ def Rake.reload!
104
+ Rake.application.clear
105
+ Rails.application.class.load_tasks
106
+ nil
107
+ end
108
+ end
109
+
110
+ if defined? Rails
111
+ require "igem/rails"
112
+ module Rails
113
+ extend IGem::Rails
114
+ end
115
+ end
116
+
117
+ if defined? Rake
118
+ require "igem/rake"
119
+ module Rake
120
+ extend IGem::Rake
121
+ end
122
+ end
123
+
124
+ module Kernel
125
+ def igem *args
126
+ IGem.run *args
127
+ end
128
+ end
129
+
data/lib/igem/rails.rb ADDED
@@ -0,0 +1,73 @@
1
+ # Run rails server and generator subcommands from the Rails console
2
+ #
3
+ # This is a solution based on http://blockgiven.tumblr.com/post/5161067729/rails-server
4
+ # Can be used to run rails server, rails generate from the Rails console thus
5
+ # speeding up Rails server startup to ~ 1 second.
6
+ #
7
+ # Usage:
8
+ # Rails.server to start the rails server
9
+ # Rails.generate to list generators
10
+ # Rails.generate "model", "user" to use a generator
11
+ # Rails.update "model", "user" to update the generated code
12
+ # Rails.destroy "model", "user" to remove the generated code
13
+ #
14
+ # NOTE: after Rails.server, you cannot use Control-C anymore in the console
15
+ # because it first stops the server, secondly stops the process
16
+ #
17
+
18
+ module IGem::Rails
19
+
20
+ def generate *args
21
+ args = args[0].split(" ") if args.count == 1
22
+ args = args.map{|e|e.to_s}
23
+ require "rails/generators"
24
+ Rails::Generators.help && return if args.empty?
25
+ name = args.shift
26
+ args << "--orm=active_record" if args.none? {|a|a =~ /--orm/}
27
+ Rails::Generators.invoke name, args, :behavior => :invoke
28
+ end
29
+
30
+ alias g generate
31
+
32
+ def destroy *args
33
+ args = args[0].split(" ") if args.count == 1
34
+ args = args.map{|e|e.to_s}
35
+ require "rails/generators"
36
+ Rails::Generators.help && return if args.empty?
37
+ name = args.shift
38
+ args << "--orm=active_record" if args.none? {|a|a =~ /--orm/}
39
+ Rails::Generators.invoke name, args, :behavior => :revoke
40
+ end
41
+
42
+ alias d destroy
43
+
44
+ def update *args
45
+ args = args[0].split(" ") if args.count == 1
46
+ args = args.map{|e|e.to_s}
47
+ require "rails/generators"
48
+ Rails::Generators.help && return if args.empty?
49
+ name = args.shift
50
+ args << "--orm=active_record" if args.none? {|a|a =~ /--orm/}
51
+ Rails::Generators.invoke name, args, :behavior => :skip
52
+ end
53
+
54
+ def server options={:Port => 3000}
55
+ require "rails/commands/server"
56
+
57
+ return @server if defined? @server and @server.alive?
58
+
59
+ if defined? @server and not @server.alive?
60
+ ObjectSpace.each_object(TCPServer){|s| s.close if !s.closed? && s.addr[1] == options[:Port]}
61
+ end
62
+
63
+ @server = Thread.new do
64
+ options[:Port] = options[:Port].to_s
65
+
66
+ server = Rails::Server.new
67
+ server.options.merge options
68
+ server.start
69
+ end
70
+ end
71
+
72
+ alias s server
73
+ end
data/lib/igem/rake.rb ADDED
@@ -0,0 +1,21 @@
1
+ module IGem::Rake
2
+ # Reloads the rake tasks. This is necessary if you want to develop your rake
3
+ # tasks and call them from the command line
4
+ #
5
+ # Usage:
6
+ #
7
+ # load "path/to/my/tasks.rake"
8
+ # igem "rake my:task"
9
+ # # see results, change code
10
+ # Rake.reload!
11
+ # load "path/to/my/tasks.rake"
12
+ # igem "rake my:task"
13
+ # ...
14
+ def reload!
15
+ Rake.application.clear
16
+ if defined? Rails
17
+ Rails.application.class.load_tasks
18
+ end
19
+ nil
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ print *ARGV
data/spec/igem_spec.rb ADDED
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require "stringio"
4
+
5
+ describe "IGem" do
6
+
7
+ before do
8
+ $stdout = StringIO.new
9
+ end
10
+
11
+ def output
12
+ $stdout.string
13
+ end
14
+
15
+ after do
16
+ $stdout = STDOUT
17
+ end
18
+
19
+ it "can execute a ruby file" do
20
+ igem "spec/helpers/example.rb hello", :fork => false
21
+ output.should == "hello"
22
+ end
23
+
24
+ it "can fork" do
25
+ igem "spec/helpers/example.rb hello", :fork => true
26
+ output.should == ""
27
+ end
28
+
29
+ it "will fork by default" do
30
+ igem "spec/helpers/example.rb hello"
31
+ output.should == ""
32
+ end
33
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'igem'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: igem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bernát Kalló
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &1 !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: *1
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &3 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *3
47
+ description: With this gem you can load gem commands from the command line with forking,
48
+ or start Rails subcommands without re-loading the whole rails environment. This
49
+ can help you speed up the Rails development.
50
+ email: kallo.bernat@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files:
54
+ - LICENSE.txt
55
+ - README.rdoc
56
+ files:
57
+ - .document
58
+ - .rspec
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - LICENSE.txt
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/igem.rb
66
+ - lib/igem/rails.rb
67
+ - lib/igem/rake.rb
68
+ - spec/helpers/example.rb
69
+ - spec/igem_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: http://github.com/cie/igem
72
+ licenses:
73
+ - MIT
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -230770835
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.15
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Load gem commands from the Rails command line with forking
99
+ test_files: []