duoconsole 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/duoconsole.rb +33 -45
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1abf14816a0573ee19583a436b6c52aac3f92891
4
- data.tar.gz: 86a8a79b0305f8d216f7e3f4b9c02a4cfbd0211b
3
+ metadata.gz: cf225ca24e2561e4b81a1225f774bac71dd52dbf
4
+ data.tar.gz: 99a99ccb9a1e6c6604c36b875a1f80e285f1f382
5
5
  SHA512:
6
- metadata.gz: 812c7af8d68a7c9e445c58d8047792bb9954ba0bcf1415ec1b0b25ca7e6768cb284ce9fdae9e790d2ba904a959d2990b4b3217fd575f646d4448f95fa5d20356
7
- data.tar.gz: 20c5f45d26ded389ecb18fe7e8845bb0f9d24537af4087f922b4136d2f490207125caf83919127c3b16913995f02427adc0aa724c747fca4b27ba1c92febd844
6
+ metadata.gz: 7288a267ea48f3977093a3862e6506eb52e2ebed1d9250521678582bb56a5d718255585f353dab6f19260c46258e71b854e8e9350846f290c200906d26fc0a48
7
+ data.tar.gz: 8882ed908a326dcf54e40b88a7ff0919c0cae5db645a16c346da9491739e82f494edbb72750b4553886bac45d23721efa132092ffbffefc8b8b5d5f622bfcd7c
data/lib/duoconsole.rb CHANGED
@@ -22,9 +22,6 @@ class Duoconsole
22
22
  if defined?(Bundler)
23
23
  Bundler.require(:default, :assets)
24
24
  end
25
-
26
- require 'commands'
27
- monkeypatch_commands_gem
28
25
  end
29
26
 
30
27
  def create_socket_pair
@@ -33,10 +30,6 @@ class Duoconsole
33
30
 
34
31
  def fork_child
35
32
  child_pid = fork do
36
- Rails.env = ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
37
-
38
- load_application
39
-
40
33
  trap(:INT) {
41
34
  # Ignore. This process needs to stay alive until the parent process exits
42
35
  }
@@ -54,18 +47,6 @@ class Duoconsole
54
47
 
55
48
  def load_application
56
49
  require APP_PATH
57
-
58
- if Rails.env.test?
59
- # Initializer copied from https://github.com/jonleighton/spring/blob/master/lib/spring/application.rb#L30
60
- #
61
- # The test environment has config.cache_classes = true set by default.
62
- # However, we don't want this to prevent us from performing class reloading,
63
- # so this gets around that.
64
- Rails::Application.initializer :initialize_dependency_mechanism, group: :all do
65
- ActiveSupport::Dependencies.mechanism = :load
66
- end
67
- end
68
-
69
50
  Rails.application.require_environment!
70
51
  end
71
52
 
@@ -81,32 +62,6 @@ class Duoconsole
81
62
  @command_client ||= CommandClient.new(parent_socket)
82
63
  end
83
64
 
84
- def monkeypatch_commands_gem
85
- Rails::Commands::TestEnvironment.module_eval do
86
- # Overriding this method to add the following behavior:
87
- # 1. fix issue with Postgres adapter and forking behavior
88
- # 2. trap INT signal and exit
89
- def fork
90
- defined?(ActiveRecord::Base) and
91
- ActiveRecord::Base.connection.disconnect!
92
-
93
- Rails::Commands::Environment.fork do
94
- defined?(ActiveRecord::Base) and
95
- ActiveRecord::Base.establish_connection
96
-
97
- setup_for_test
98
-
99
- trap(:INT) {
100
- $stderr.flush
101
- exit
102
- }
103
-
104
- yield
105
- end
106
- end
107
- end
108
- end
109
-
110
65
 
111
66
  class CommandClient
112
67
  attr_reader :socket
@@ -135,6 +90,7 @@ class Duoconsole
135
90
  # Clear it out now so that it won't be in the buffer for next run
136
91
  socket.recv(1000)
137
92
  raise e
93
+ # e.class.name
138
94
  end
139
95
  end
140
96
 
@@ -153,6 +109,7 @@ class Duoconsole
153
109
  command, args = Marshal.load(msg)
154
110
 
155
111
  retval = if valid_command?(command)
112
+ require_app unless @app_required
156
113
  run_command(command, args)
157
114
  else
158
115
  "Unrecognized command. Valid commands are #{RECOGNIZED_COMMANDS.join(', ')}"
@@ -183,6 +140,37 @@ class Duoconsole
183
140
  puts "#{e.class}: #{e.message}"
184
141
  puts e.backtrace.map {|line| "\t#{line}"}
185
142
  end
143
+
144
+ def require_app
145
+ Rails.env = ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
146
+ require APP_PATH
147
+ require 'commands'
148
+ monkeypatch_commands_gem
149
+ @app_required = true
150
+ end
151
+
152
+ def monkeypatch_commands_gem
153
+ Rails::Commands::TestEnvironment.module_eval do
154
+ def fork
155
+ Rails::Commands::Environment.fork do
156
+ trap(:INT) {
157
+ $stderr.flush
158
+ exit
159
+ }
160
+
161
+ Rails.application.require_environment!
162
+
163
+ if defined?(ActiveRecord::Base)
164
+ ActiveRecord::Base.establish_connection
165
+ end
166
+
167
+ add_test_dir_to_load_path
168
+
169
+ yield
170
+ end
171
+ end
172
+ end
173
+ end
186
174
  end
187
175
 
188
176
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duoconsole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Buesing
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-18 00:00:00.000000000 Z
11
+ date: 2013-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  requirements: []
69
69
  rubyforge_project:
70
- rubygems_version: 2.0.0
70
+ rubygems_version: 2.0.3
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: Launch Rails development console with test environment as a child process