Class: Gitdocs::Manager
- Inherits:
-
Object
- Object
- Gitdocs::Manager
- Defined in:
- lib/gitdocs/manager.rb
Defined Under Namespace
Classes: RepoDescriptor
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
Instance Method Summary collapse
-
#initialize(config_root, debug) {|@config| ... } ⇒ Manager
constructor
A new instance of Manager.
- #restart ⇒ Object
- #search(term) ⇒ Object
- #start(web_port = nil) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config_root, debug) {|@config| ... } ⇒ Manager
Returns a new instance of Manager.
7 8 9 10 11 12 |
# File 'lib/gitdocs/manager.rb', line 7 def initialize(config_root, debug) @config = Configuration.new(config_root) @logger = Logger.new(File.('log', @config.config_root)) @debug = debug yield @config if block_given? end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/gitdocs/manager.rb', line 5 def config @config end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
5 6 7 |
# File 'lib/gitdocs/manager.rb', line 5 def debug @debug end |
Instance Method Details
#restart ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/gitdocs/manager.rb', line 76 def restart Thread.new do Thread.main.raise Restart, "restarting ... " sleep 0.1 while EM.reactor_running? start end end |
#search(term) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/gitdocs/manager.rb', line 16 def search(term) results = {} @runners.each_with_index do |runner, index| descriptor = RepoDescriptor.new(runner.root, index) repo_results = runner.search(term) results[descriptor] = repo_results unless repo_results.empty? end results end |
#start(web_port = nil) ⇒ Object
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 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gitdocs/manager.rb', line 26 def start(web_port=nil) self.log "Starting Gitdocs v#{VERSION}..." self.log "Using configuration root: '#{self.config.config_root}'" self.log "Shares: #{config.shares.map(&:inspect).join(", ")}" # Start the repo watchers runners = nil = false begin EM.run do self.log "Starting EM loop..." @runners = config.shares.map { |share| self.log "Starting #{share}" Runner.new(share) } self.log "Running runners... #{@runners.size}" @runners.each(&:run) # Start the web front-end if self.config.global.start_web_frontend web_port ||= self.config.global.web_frontend_port Server.new(self, *@runners).start(web_port.to_i) EM.defer( proc { i = 0 web_started = false begin TCPSocket.open('127.0.0.1', web_port.to_i).close web_started = true rescue Errno::ECONNREFUSED self.log "Retrying server loop..." sleep 0.2 i += 1 retry if i <= 20 end system("open http://localhost:#{web_port}/") if ! && self.config.global.load_browser_on_startup && web_started }, proc { self.log "Web server running!" }) end end rescue Restart = true retry end rescue Exception => e # Report all errors in log self.log(e.class.inspect + " - " + e.inspect + " - " + e..inspect, :error) self.log(e.backtrace.join("\n"), :error) raise ensure self.log("Gitdocs is terminating...goodbye\n\n") end |
#stop ⇒ Object
84 85 86 |
# File 'lib/gitdocs/manager.rb', line 84 def stop EM.stop end |