class DockDriver::Dock
Manages the dock process and templating.
Constants
- CONFIG_DEFAULTS
The default configuration for this class.
Attributes
command[RW]
The dock command to run and pipe the template result to.
config[RW]
The loaded config.
icon_color[RW]
Icon Color Set
items[RW]
The configuration for each user-specified DockItem
.
template[RW]
The dock’s output raw ERB template string.
items[RW]
A hash of the dock items in use.
Public Class Methods
configure( section )
click to toggle source
Configure the class.
# File lib/dock_driver/dock.rb, line 43 def self::configure( section ) self.config = CONFIG_DEFAULTS.merge( section || {} ) self.command = self.config[:command] self.items = self.config[:items] || {} self.template = self.config[:template] end
Public Instance Methods
kill()
click to toggle source
Shut down the dock gracefully.
# File lib/dock_driver/dock.rb, line 111 def kill begin self.log.debug 'Killed.' rescue ThreadError # We can't write to the log from the trap context. end self.items.map { |name,item| item.thread.kill } self.items.clear @pipe.close if @pipe and not @pipe.closed? @pipe = nil end
pipe()
click to toggle source
Lazily execute the dock command.
# File lib/dock_driver/dock.rb, line 64 def pipe return @pipe ||= IO.popen( self.class.command, 'w' ) end
restart()
click to toggle source
Restart the dock.
# File lib/dock_driver/dock.rb, line 101 def restart self.log.debug 'Killed.' self.items.map { |name,item| item.thread.kill } self.items.clear @pipe.close if @pipe and not @pipe.closed? @pipe = nil self.run end
run()
click to toggle source
Start or restart the dock.
# File lib/dock_driver/dock.rb, line 85 def run self.log.debug "Building items from config." self.items.map { |name,item| item.thread.kill } self.items = self.class.items.inject( {} ) do |hash,opts| item = DockItem.new( opts ) item.add_observer self hash[item.name] = item hash end self.log.debug "Starting items." self.items.map { |name,item| item.thread.run } end
update( obj = self )
click to toggle source
Listen to this dock’s items, printing to the dock command when appropriate.
# File lib/dock_driver/dock.rb, line 70 def update( obj = self ) @lock.synchronize do begin self.pipe.puts Template.render( self.class.template, self.items ) rescue Exception => e self.log.error "Unable to write to the dock." self.log.error e.message $stderr.puts e.backtrace exit end end end