rrails 0.1.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/Gemfile ADDED
@@ -0,0 +1,14 @@
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 "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler"
12
+ gem "jeweler", "~> 1.8.3"
13
+ gem "simplecov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.6.6)
11
+ multi_json (1.3.2)
12
+ rake (0.9.2.2)
13
+ rdoc (3.12)
14
+ json (~> 1.4)
15
+ shoulda (3.0.1)
16
+ shoulda-context (~> 1.0.0)
17
+ shoulda-matchers (~> 1.0.0)
18
+ shoulda-context (1.0.0)
19
+ shoulda-matchers (1.0.0)
20
+ simplecov (0.6.1)
21
+ multi_json (~> 1.0)
22
+ simplecov-html (~> 0.5.3)
23
+ simplecov-html (0.5.3)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler
30
+ jeweler (~> 1.8.3)
31
+ rdoc (~> 3.12)
32
+ shoulda
33
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Keiji, Yoshimi
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,38 @@
1
+ = rrails
2
+
3
+ remote run rails/rake command.
4
+
5
+ == Usage
6
+
7
+ $ cd ~/rails_project
8
+ $ bundle exec rrails-server
9
+
10
+ $ rrails -- rails generate model Yakiniku
11
+
12
+ $ rrails -E test -- rake db:migrate
13
+
14
+ == Description
15
+
16
+ rails command is too slow. and rake command is too slow under rails environment.
17
+ So, rrails can run rails/rake commands by preloaded daemon.
18
+
19
+ == SEE ALSO
20
+
21
+ * guard-rrails: https://github.com/walf443/guard-rrails
22
+ * rails-sh: https://github.com/jugyo/rails-sh
23
+
24
+ == Contributing to rrails
25
+
26
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
27
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
28
+ * Fork the project.
29
+ * Start a feature/bugfix branch.
30
+ * Commit and push until you are happy with your contribution.
31
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
32
+ * 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.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2012 Keiji, Yoshimi. See LICENSE.txt for
37
+ further details.
38
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
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 = "rrails"
18
+ gem.homepage = "http://github.com/walf443/rrails"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{remote run rails/rake command}
21
+ gem.description = %Q{remote run rails/rake command}
22
+ gem.email = "walf443@gmail.com"
23
+ gem.authors = ["Keiji, Yoshimi"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "rrails #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/rrails ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'rrails'
5
+ require 'rrails/client'
6
+ RemoteRails::Client.new_with_options(ARGV).run
data/bin/rrails-server ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["RAILS_ENV"] ||= ARGV.shift
4
+ $:.unshift File.expand_path('../../lib', __FILE__)
5
+ require 'rrails'
6
+ require 'rrails/server'
7
+ RemoteRails::Server.new.start
@@ -0,0 +1,41 @@
1
+ require 'socket'
2
+ require 'rrails'
3
+ require 'shellwords'
4
+ require 'optparse'
5
+ module RemoteRails
6
+ class Client
7
+ def self.new_with_options(argv)
8
+ options = {}
9
+ opts = OptionParser.new
10
+ opts.on('-E', '--rails_env=s') {|v| options[:rails_env] = v }
11
+ opts.on('-p', '--port=i') {|v| options[:port] = v }
12
+ opts.parse!(argv)
13
+
14
+ cmd = Shellwords.join(argv)
15
+ options[:cmd] = cmd == "" ? nil : cmd
16
+ self.new(options)
17
+ end
18
+
19
+ def initialize(options={})
20
+ @cmd = options[:cmd] || "rails"
21
+ @rails_env = options[:rails_env] || 'development'
22
+ @host = options[:host] || 'localhost'
23
+ @port = options[:port] || DEFAULT_PORT[@rails_env]
24
+ end
25
+
26
+ def run
27
+ sock = TCPSocket.open(@host, @port)
28
+ sock.puts(@cmd)
29
+ while line = sock.gets
30
+ if line =~ /^FINISHED\t(.+)/
31
+ $stdout.puts("\nfinished (#{$1}sec)")
32
+ return
33
+ elsif line =~ /^OUT\t(.+)$/
34
+ $stdout.puts($1)
35
+ elsif line =~ /^ERROR\t(.+)$/
36
+ $stderr.puts($1)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,116 @@
1
+ require 'socket'
2
+ require 'rrails'
3
+ require 'logger'
4
+ require 'rake'
5
+ require 'stringio'
6
+ require 'shellwords'
7
+
8
+ # FIXME: rails command require APP_PATH constants.
9
+ APP_PATH = File.expand_path('./config/application')
10
+
11
+ module RemoteRails
12
+ class Server
13
+ def initialize(options={})
14
+ @rails_env = options[:rails_env] || "development"
15
+ @app_path = File.expand_path('./config/application')
16
+ # should not access to outside
17
+ @host = 'localhost'
18
+ @port = options[:poot] || DEFAULT_PORT[@rails_env]
19
+ @logger = Logger.new(options[:logfile] ? options[:logfile] : $stderr)
20
+ end
21
+
22
+ def boot_rails
23
+ @logger.info("prepare rails environment")
24
+ ENV["RAILS_ENV"] = @rails_env
25
+ require File.expand_path('./config/boot')
26
+ require @app_path
27
+ Rails.application.require_environment!
28
+ @logger.info("finished preparing rails environment")
29
+ end
30
+
31
+ def start
32
+ self.boot_rails
33
+ server = TCPServer.open(@host, @port)
34
+ @logger.info("starting rrails server on #{@host}:#{@port}")
35
+ trap(:INT) do
36
+ @logger.info("SIGINT recieved. shutdown...")
37
+ exit
38
+ end
39
+ trap(:TERM) do
40
+ @logger.info("SIGTERM recieved. shutdown...")
41
+ exit
42
+ end
43
+ trap(:HUP) do
44
+ @logger.info("SIGHUP recieved. reload...")
45
+ ActionDispatch::Callbacks.new(Proc.new {}).call({})
46
+ self.boot_rails
47
+ end
48
+ Thread.abort_on_exception = true
49
+ loop do
50
+ Thread.start(server.accept) do |s|
51
+ begin
52
+ while line = s.gets
53
+ line.chomp!
54
+ @logger.info("invoke: #{line}")
55
+ start = Time.now
56
+ self.dispatch(s, line)
57
+ finish = Time.now
58
+ s.puts("FINISHED\t#{ finish - start }")
59
+ @logger.info("finished: #{line}")
60
+ end
61
+ rescue Errno::EPIPE => e
62
+ @logger.error("client disconnect: " + e.message)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def dispatch(sock, line)
69
+ args = Shellwords.shellsplit(line)
70
+ subcmd = args.shift
71
+ ActiveRecord::Base.remove_connection if defined?(ActiveRecord::Base)
72
+ servsock_out, clisock_out = UNIXSocket.pair
73
+ servsock_err, clisock_err = UNIXSocket.pair
74
+ pid = fork do
75
+ clisock_out.close
76
+ clisock_err.close
77
+ ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
78
+ STDOUT.reopen(servsock_out)
79
+ STDERR.reopen(servsock_err)
80
+ self.__send__("on_#{subcmd}", args)
81
+ end
82
+ servsock_out.close
83
+ servsock_err.close
84
+ loop do
85
+ if Process.waitpid(pid, Process::WNOHANG)
86
+ return
87
+ end
88
+ if IO.select([clisock_out], [], [], 0.1)
89
+ while line = clisock_out.gets
90
+ line.chomp!
91
+ sock.puts("OUT\t#{line}")
92
+ end
93
+ end
94
+ if IO.select([clisock_err], [], [], 0.1)
95
+ while line = clisock_err.gets
96
+ line.chomp!
97
+ @logger.error(line)
98
+ sock.puts("ERROR\t#{line}")
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ def on_rails(args)
105
+ ARGV.clear
106
+ ARGV.concat(args)
107
+ require 'rails/commands'
108
+ end
109
+
110
+ def on_rake(args)
111
+ ARGV.clear
112
+ ARGV.concat(args)
113
+ ::Rake.application.run
114
+ end
115
+ end
116
+ end
data/lib/rrails.rb ADDED
@@ -0,0 +1,7 @@
1
+ module RemoteRails
2
+ DEFAULT_PORT = {
3
+ "development" => 5656,
4
+ "test" => 5657,
5
+ "production" => 5658,
6
+ }
7
+ end
data/rrails.gemspec ADDED
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rrails"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Keiji, Yoshimi"]
12
+ s.date = "2012-05-01"
13
+ s.description = "remote run rails/rake command"
14
+ s.email = "walf443@gmail.com"
15
+ s.executables = ["rrails", "rrails-server"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/rrails",
29
+ "bin/rrails-server",
30
+ "lib/rrails.rb",
31
+ "lib/rrails/client.rb",
32
+ "lib/rrails/server.rb",
33
+ "rrails.gemspec",
34
+ "test/helper.rb",
35
+ "test/test_rrails.rb"
36
+ ]
37
+ s.homepage = "http://github.com/walf443/rrails"
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.21"
41
+ s.summary = "remote run rails/rake command"
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
51
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
57
+ s.add_dependency(%q<simplecov>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<shoulda>, [">= 0"])
61
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
+ s.add_dependency(%q<bundler>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
64
+ s.add_dependency(%q<simplecov>, [">= 0"])
65
+ end
66
+ end
67
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rrails'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRrails < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rrails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Keiji, Yoshimi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
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: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
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
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: remote run rails/rake command
95
+ email: walf443@gmail.com
96
+ executables:
97
+ - rrails
98
+ - rrails-server
99
+ extensions: []
100
+ extra_rdoc_files:
101
+ - LICENSE.txt
102
+ - README.rdoc
103
+ files:
104
+ - .document
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.rdoc
109
+ - Rakefile
110
+ - VERSION
111
+ - bin/rrails
112
+ - bin/rrails-server
113
+ - lib/rrails.rb
114
+ - lib/rrails/client.rb
115
+ - lib/rrails/server.rb
116
+ - rrails.gemspec
117
+ - test/helper.rb
118
+ - test/test_rrails.rb
119
+ homepage: http://github.com/walf443/rrails
120
+ licenses:
121
+ - MIT
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: -3230074702185761932
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.21
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: remote run rails/rake command
147
+ test_files: []