duoconsole 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/duoconsole.rb +24 -12
  2. metadata +2 -2
data/lib/duoconsole.rb CHANGED
@@ -13,7 +13,6 @@ class Duoconsole
13
13
  create_socket_pair
14
14
  fork_child
15
15
  load_application
16
- initialize_command_client
17
16
  start_console
18
17
  end
19
18
 
@@ -25,6 +24,7 @@ class Duoconsole
25
24
  end
26
25
 
27
26
  require 'commands'
27
+ monkeypatch_commands_gem
28
28
  end
29
29
 
30
30
  def create_socket_pair
@@ -36,7 +36,6 @@ class Duoconsole
36
36
  Rails.env = ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
37
37
 
38
38
  load_application
39
- monkeypatch_test_environment
40
39
 
41
40
  trap(:INT) {
42
41
  # Ignore. This process needs to stay alive until the parent process exits
@@ -70,29 +69,42 @@ class Duoconsole
70
69
  Rails.application.require_environment!
71
70
  end
72
71
 
73
- def initialize_command_client
74
- ConsoleDelegation.command_client = CommandClient.new(parent_socket)
75
- end
76
-
77
72
  def start_console
78
73
  require 'rails/commands/console'
79
74
  require 'rails/console/app'
75
+ ConsoleDelegation.duoconsole = self
80
76
  Rails::ConsoleMethods.send :include, ConsoleDelegation
81
77
  Rails::Console.start(Rails.application)
82
78
  end
83
79
 
84
- def monkeypatch_test_environment
80
+ def command_client
81
+ @command_client ||= CommandClient.new(parent_socket)
82
+ end
83
+
84
+ def monkeypatch_commands_gem
85
85
  Rails::Commands::TestEnvironment.module_eval do
86
86
  # Overriding this method to add the following behavior:
87
87
  # 1. fix issue with Postgres adapter and forking behavior
88
88
  # 2. trap INT signal and exit
89
89
  def fork
90
- ActiveRecord::Base.clear_active_connections!
90
+ clear_active_record_connections
91
+
91
92
  Rails::Commands::Environment.fork do
92
93
  setup_for_test
93
- trap(:INT) { exit(1) }
94
+
95
+ trap(:INT) {
96
+ $stderr.flush
97
+ exit
98
+ }
94
99
 
95
100
  yield
101
+
102
+ clear_active_record_connections
103
+ end
104
+ end
105
+
106
+ def clear_active_record_connections
107
+ if defined? ActiveRecord
96
108
  ActiveRecord::Base.clear_active_connections!
97
109
  end
98
110
  end
@@ -165,12 +177,12 @@ class Duoconsole
165
177
 
166
178
 
167
179
  module ConsoleDelegation
168
- def self.command_client= client
169
- @@command_client = client
180
+ def self.duoconsole= dc
181
+ @@duoconsole = dc
170
182
  end
171
183
 
172
184
  def testenv
173
- @@command_client
185
+ @@duoconsole.command_client
174
186
  end
175
187
 
176
188
  def test *args
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duoconsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-30 00:00:00.000000000 Z
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails