rails-sh 1.2.5 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.2.6
data/lib/rails/sh/rake.rb CHANGED
@@ -17,7 +17,9 @@ module Rails
17
17
 
18
18
  def invoke(line)
19
19
  name, *args = line.split(/\s+/)
20
+ run_before_fork
20
21
  pid = fork do
22
+ run_after_fork
21
23
  args.each do |arg|
22
24
  env, value = arg.split('=')
23
25
  next unless env && !env.empty? && value && !value.empty?
@@ -31,6 +33,22 @@ module Rails
31
33
  def task_names
32
34
  ::Rake.application.tasks.map{|t| t.name}
33
35
  end
36
+
37
+ def before_fork(&block)
38
+ @before_fork = block
39
+ end
40
+
41
+ def after_fork(&block)
42
+ @after_fork = block
43
+ end
44
+
45
+ def run_before_fork(&block)
46
+ @before_fork.call if @before_fork
47
+ end
48
+
49
+ def run_after_fork(&block)
50
+ @after_fork.call if @after_fork
51
+ end
34
52
  end
35
53
  end
36
54
  end
data/lib/rails/sh.rb CHANGED
@@ -10,9 +10,18 @@ module Rails
10
10
 
11
11
  class << self
12
12
  def start
13
- Rails::Sh::Rake.init
13
+ before_fork do
14
+ ActiveRecord::Base.remove_connection if defined?(ActiveRecord::Base)
15
+ end
16
+ after_fork do
17
+ ActiveRecord::Base.establish_connection if defined?(ActiveRecord::Base)
18
+ end
19
+
20
+ init_rake
21
+
14
22
  puts "Rails.env: #{Rails.env}"
15
23
  puts "type `help` to print help"
24
+
16
25
  setup_readline
17
26
  while buf = Readline.readline("rails> ", true)
18
27
  line = buf.strip
@@ -28,6 +37,32 @@ module Rails
28
37
  end
29
38
  end
30
39
 
40
+ def init_rake
41
+ Rails::Sh::Rake.init
42
+ Rails::Sh::Rake.before_fork do
43
+ run_before_fork
44
+ end
45
+ Rails::Sh::Rake.after_fork do
46
+ run_after_fork
47
+ end
48
+ end
49
+
50
+ def before_fork(&block)
51
+ @before_fork = block
52
+ end
53
+
54
+ def after_fork(&block)
55
+ @after_fork = block
56
+ end
57
+
58
+ def run_before_fork(&block)
59
+ @before_fork.call if @before_fork
60
+ end
61
+
62
+ def run_after_fork(&block)
63
+ @after_fork.call if @after_fork
64
+ end
65
+
31
66
  def setup_readline
32
67
  Readline.basic_word_break_characters = ""
33
68
  Readline.completion_proc = lambda do |word|
@@ -51,7 +86,9 @@ module Rails
51
86
  end
52
87
 
53
88
  def execute_rails_command(line)
89
+ run_before_fork
54
90
  pid = fork do
91
+ run_after_fork
55
92
  ARGV.clear
56
93
  ARGV.concat line.split(/\s+/)
57
94
  puts "\e[42m$ rails #{ARGV.join(" ")}\e[0m"
data/rails-sh.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails-sh}
8
- s.version = "1.2.5"
8
+ s.version = "1.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rails-sh
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.5
5
+ version: 1.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo