Class: Boing::Runner
- Inherits:
-
Object
- Object
- Boing::Runner
- Defined in:
- lib/boing.rb
Constant Summary collapse
- INPROC_RAILS_CMDS =
%w[c console r runner g generate d destroy]
Instance Method Summary collapse
-
#initialize(args) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Runner
Returns a new instance of Runner.
8 9 10 |
# File 'lib/boing.rb', line 8 def initialize(args) @args = args.dup end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/boing.rb', line 12 def run # warn if we're not in drip; and if not, load dripmain.rb as well if ENV['DRIP_INIT_CLASS'] == nil $stderr.puts "Note: Not running in drip; may be booting or configured wrong" dripmain = File.join(Dir.pwd, 'dripmain.rb') if File.exist?(dripmain) load dripmain end end # check for known "special" commands if @args[0] == 'rails' && INPROC_RAILS_COMMANDS.include?(@args[1]) # running a `rails` command # best value comes from prebooting rails, so warn if not prebooted if !defined?(Rails) $stderr.puts "Note: Running Rails commands but Rails is not prebooted." require File.join(Dir.pwd, 'config/application.rb') end # commands that just reboot rails can run in-process @args.shift Object.const_set(:APP_PATH, ::Rails.root.join("config/application")) require "rails/commands" exit elsif @args[0] == 'killall' # kill all drip instances $stderr.puts "Killing all drip instances" system "drip kill" exit elsif @args[0] == 'dripmain' # Install a basic dripmain.rb for Rails use if !File.exist? File.('./config/application.rb') $stderr.puts "#{Dir.pwd} does not appear to be a rails application." exit end if File.exist? 'dripmain.rb' FileUtils.cp 'dripmain.rb', 'dripmain.rb.bak' end File.open('dripmain.rb', 'w') do |f| f.puts("require File.expand_path('../config/application', __FILE__)") end exit end # All other commands run as is cmd = @args.shift load File.join(File.dirname(Gem.ruby), cmd) end |