Class | Rascut::Command |
In: |
lib/rascut/command.rb
|
Parent: | Object |
config | [R] | |
file_observer | [R] | |
logger | [RW] | |
root | [R] | |
target_script | [R] | |
wrapper | [R] |
# File lib/rascut/command.rb, line 13 13: def initialize 14: @logger = Logger.new(STDOUT) 15: @httpd = nil 16: end
# File lib/rascut/command.rb, line 103 103: def compile_success_proc 104: if @httpd 105: @httpd.reload! 106: end 107: end
# File lib/rascut/command.rb, line 136 136: def exit 137: logger.info 'exiting...' 138: begin 139: @wrapper.close 140: @httpd.stop if @httpd 141: rescue Exception => e 142: logger.error e.inspect 143: end 144: Kernel::exit 1 145: end
# File lib/rascut/command.rb, line 64 64: def init_plugins 65: @config[:plugin].each do |name| 66: klass_name = name.gsub(/(^|_)(.)/) { $2.upcase } 67: logger.info "Load Plugin: #{klass_name}" 68: require "rascut/plugin/#{name}" 69: ::Rascut::Plugin.const_get(klass_name).new(self).run 70: end if @config[:plugin] 71: end
# File lib/rascut/command.rb, line 77 77: def read_log_loop 78: log = Pathname.new(@config.params[:flashlog]) 79: return unless (log && log.file?) 80: 81: Thread.new(log) do |log| 82: flashlog_timestamp ||= log.mtime 83: 84: log.open('r') do |f| 85: f.read 86: loop do 87: if log.mtime > flashlog_timestamp 88: f.rewind 89: text = f.read 90: if text.length == 0 91: f.rewind 92: text = f.read 93: end 94: logger.info("FLASHLOG\n" + text) unless text.strip.empty? 95: flashlog_timestamp = log.mtime 96: end 97: sleep 1 98: end 99: end 100: end 101: end
# File lib/rascut/command.rb, line 19 19: def run(argv) 20: @config = Config.new 21: 22: if home.parent && home.parent.join('.rascutrc').readable? 23: @config.merge_config home.parent.join('.rascutrc') 24: end 25: 26: if File.readable?('.rascut') && File.file?('.rascut') 27: config.merge_config('.rascut') 28: end 29: 30: @config.parse_argv!(argv) 31: 32: unless @target_script = argv.first 33: warn 'Target script is not found.' 34: Kernel::exit 1 35: end 36: 37: @root = Pathname.new(@target_script).dirname.realpath 38: @wrapper = FcshWrapper.new(@target_script, @config) 39: 40: start_server if @config[:server] 41: setting_signals 42: @wrapper.hooks[:compile_success] << method(:compile_success_proc) 43: 44: 45: if @config[:file_observing] 46: @file_observer = FileObserver.new(@config[:observe_files], 47: :interval => @config[:interval], 48: :ext => @config[:ext], 49: :logger => @config[:logger], 50: :update_handler => method(:file_update_handler)) 51: @file_observer.run 52: end 53: 54: read_log_loop if @config[:flashlog] 55: 56: init_plugins 57: 58: @wrapper.compile 59: #readline_loop 60: Thread.stop 61: end
# File lib/rascut/command.rb, line 115 115: def setting_signals 116: methods(true).each do |mname| 117: if m = mname.match(/^sig_(.+)$/) 118: begin 119: Signal.trap(m[1].upcase) { method(mname).call } 120: rescue ArgumentError 121: end 122: end 123: end 124: end
# File lib/rascut/command.rb, line 126 126: def sig_int 127: logger.debug 'SIG_INT' 128: self.exit() 129: end
# File lib/rascut/command.rb, line 131 131: def sig_usr2 132: logger.debug 'SIG_USR2' 133: @wrapper.compile 134: end