class Dumon::App
This class represents an entry point
Attributes
current_profile[RW]
Currently used profile.
ui[R]
User interface of Dumon
tool.
Public Class Methods
new()
click to toggle source
Constructor.
# File lib/dumon.rb, line 43 def initialize @ui = new_ui Dumon::logger.debug "Used UI: #{ui.class.name}" end
Public Instance Methods
config_file(mode='r')
click to toggle source
Gets default config file.
# File lib/dumon.rb, line 63 def config_file(mode='r') homedir = RUBY_VERSION < '1.9' ? ENV['HOME'] : Dir.home filename = "#{homedir}#{File::SEPARATOR}.config#{File::SEPARATOR}dumon.conf" # check and create directory structure dirname = File.dirname filename ::FileUtils.mkdir_p(dirname) unless File.exist?(dirname) # create file if does not exist File.open(filename, 'w').close unless File.exist? filename File.open(filename, mode) end
new_ui(with=Dumon::GtkTrayUi)
click to toggle source
Factory method to create a new object of UI.<p/> Can be used as Dependency Injection (DI) entry point: you can reopen Dumon:App and redefine ‘new_ui’ if you implement a new UI class. <pre> class Dumon::App
def new_ui; Dumon::XyUi.new; end
end </pre>
# File lib/dumon.rb, line 57 def new_ui(with=Dumon::GtkTrayUi) with.new end
quit()
click to toggle source
Quits cleanly the application.
# File lib/dumon.rb, line 127 def quit ui.quit Dumon::logger.info 'Terminted...' end
read_config()
click to toggle source
Reads Dumon’s configuration.
# File lib/dumon.rb, line 79 def read_config conf = read config_file conf = keys_to_sym conf # there can be a hook if config version is old conf = verify_and_sanitize_options conf, {:version => VERSION, :profiles => {}, :post_switch => :optional} conf end
run(daemon=false)
click to toggle source
Runs the application.
# File lib/dumon.rb, line 98 def run(daemon=false) # profile prof_arg = ARGV.select {|i| i.start_with? 'profile:'}.first unless prof_arg.nil? prof_name = prof_arg.split(':')[1] conf = read_config raise "unknown profile, name=#{prof_name}" unless conf[:profiles][prof_name.to_sym] Dumon::logger.info "Started with profile '#{prof_name}'" ui.apply_profile(conf, prof_name) end # daemon mode if daemon if RUBY_VERSION < '1.9' Dumon::logger.warn 'Daemon mode supported only in Ruby >= 1.9' else # Daemonize the process # - stay in the current directory # - don't redirect standard input, standard output and standard error to /dev/null Dumon::logger.info 'Running as daemon...' Process.daemon(true, true) end end ui.render end
write_config(conf)
click to toggle source
Writes Dumon’s configuration.
# File lib/dumon.rb, line 91 def write_config(conf) conf[:version] = VERSION write(conf, config_file('w')) end