Class Rascut::Command
In: lib/rascut/command.rb
Parent: Object

Methods

Attributes

config  [R] 
file_observer  [R] 
logger  [RW] 
root  [R] 
target_script  [R] 
wrapper  [R] 

Public Class methods

[Source]

    # File lib/rascut/command.rb, line 10
10:     def initialize
11:       @logger = Logger.new(STDOUT)
12:     end

Public Instance methods

[Source]

     # File lib/rascut/command.rb, line 105
105:     def compile_success_proc
106:       if @httpd
107:         @httpd.reload!
108:       end
109:     end

[Source]

     # File lib/rascut/command.rb, line 138
138:     def exit
139:       logger.info 'exiting...'
140:       begin
141:         @wrapper.close 
142:       rescue Exception => e
143:         logger.error e.inspect
144:       end
145:       Kernel::exit 1
146:     end

[Source]

    # File lib/rascut/command.rb, line 75
75:     def file_update_handler
76:       @wrapper.compile
77:     end

[Source]

    # File lib/rascut/command.rb, line 66
66:     def init_plugins
67:       @config[:plugin].each do |name|
68:         klass_name = name.gsub(/(^|_)(.)/) { $2.upcase }
69:         logger.info "Load Plugin: #{klass_name}"
70:         require "rascut/plugin/#{name}"
71:         ::Rascut::Plugin.const_get(klass_name).new(self).run
72:       end if @config[:plugin]
73:     end

[Source]

     # File lib/rascut/command.rb, line 79
 79:     def read_log_loop
 80:       log = Pathname.new(@config.params[:flashlog])
 81:       return unless (log && log.file?)
 82: 
 83:       Thread.new(log) do |log|
 84:         flashlog_timestamp ||= log.mtime
 85: 
 86:         log.open('r') do |f|
 87:           f.read
 88:           loop do
 89:             if log.mtime > flashlog_timestamp
 90:               f.rewind
 91:               text = f.read
 92:               if text.length == 0
 93:                 f.rewind
 94:                 text = f.read
 95:               end
 96:               logger.info("FLASHLOG\n" + text) unless text.strip.empty?
 97:               flashlog_timestamp = log.mtime
 98:             end
 99:             sleep 1
100:           end
101:         end
102:       end
103:     end

[Source]

    # File lib/rascut/command.rb, line 15
15:     def run(argv)
16:       @config = Config.new
17: 
18:       if ENV['HOME']
19:         home = Pathname.new ENV['HOME']
20:       end
21: 
22:       home.join('.rascut').mkpath if home
23: 
24:       if home && home.join('.rascutrc').readable?
25:         @config.merge_config home.join('.rascutrc')
26:       end
27: 
28:       if File.readable?('.rascut') && File.file?('.rascut') 
29:         @config.merge_config('.rascut')
30:       end
31: 
32:       @config.parse_argv!(argv)
33: 
34:       unless @target_script = argv.first
35:         warn 'Target script is not found.'
36:         Kernel::exit 1
37:       end
38: 
39:       @root = Pathname.new(@target_script).dirname.realpath
40:       @wrapper = FcshWrapper.new(@target_script, @config)
41: 
42:       start_server if @config[:server]
43:       setting_signals
44:       @wrapper.hooks[:compile_success] << method(:compile_success_proc)
45: 
46: 
47:       if @config[:file_observing]
48:         @file_observer = FileObserver.new(@config[:observe_files], 
49:                                           :interval => @config[:interval],
50:                                           :ext => @config[:ext],
51:                                           :logger => @config[:logger],
52:                                           :update_handler => method(:file_update_handler))
53:         @file_observer.run
54:       end
55: 
56:       read_log_loop if @config[:flashlog] 
57: 
58:       init_plugins
59: 
60:       @wrapper.compile 
61:       #readline_loop
62:       Thread.stop
63:     end

[Source]

     # File lib/rascut/command.rb, line 117
117:     def setting_signals
118:       methods(true).each do |mname|
119:         if m = mname.match(/^sig_(.+)$/)
120:           begin
121:             Signal.trap(m[1].upcase) { method(mname).call }
122:           rescue ArgumentError
123:           end
124:         end
125:       end
126:     end

[Source]

     # File lib/rascut/command.rb, line 128
128:     def sig_int
129:       logger.debug 'SIG_INT'
130:       self.exit()
131:     end

[Source]

     # File lib/rascut/command.rb, line 133
133:     def sig_usr2
134:       logger.debug 'SIG_USR2'
135:       @wrapper.compile
136:     end

[Source]

     # File lib/rascut/command.rb, line 111
111:     def start_server
112:       require 'rascut/httpd'
113:       @httpd = Httpd.new(self)
114:       @httpd.start
115:     end

[Validate]