Class: Rgtk::App
Instance Method Summary collapse
- #app_name ⇒ Object
- #config ⇒ Object
- #connect_db ⇒ Object
- #destroy ⇒ Object
- #extend_load_path ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #load_controllers ⇒ Object
- #load_models ⇒ Object
- #logger(kind = :application) ⇒ Object
- #root ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ App
9 10 11 12 13 14 |
# File 'lib/rgtk/app.rb', line 9 def initialize @name = self.class.name @controllers = {} @loggers = {} extend_load_path end |
Instance Method Details
#app_name ⇒ Object
20 21 22 |
# File 'lib/rgtk/app.rb', line 20 def app_name @app_name ||= self.class.name.underscore.gsub(/_app/, '') end |
#config ⇒ Object
63 64 65 66 67 68 |
# File 'lib/rgtk/app.rb', line 63 def config unless @config @config = Rgtk::Config.new end @config end |
#connect_db ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/rgtk/app.rb', line 74 def connect_db require 'activerecord' config.database ||= {:adapter => 'sqlite3', :database => data_file("#{app_name}.sqlite3")} ActiveRecord::Base.establish_connection(config.database.symbolize_keys!) ActiveRecord::Base.logger = logger(:database) end |
#destroy ⇒ Object
94 95 96 97 |
# File 'lib/rgtk/app.rb', line 94 def destroy config.save! unless config.autosave? == false Gtk.main_quit end |
#extend_load_path ⇒ Object
35 36 37 38 |
# File 'lib/rgtk/app.rb', line 35 def extend_load_path $LOAD_PATH.unshift(controllers_dir) $LOAD_PATH.unshift(models_dir) end |
#load_controllers ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rgtk/app.rb', line 40 def load_controllers Dir[File.join(controllers_dir, '**', '*')].each do |controller_file_name| controller_name = File.basename(controller_file_name, '.rb') require controller_name end end |
#load_models ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rgtk/app.rb', line 47 def load_models connect_db if config.use_db? Dir[File.join(models_dir, '**', '*')].each do |model_file_name| model_name = File.basename(model_file_name, '.rb') require model_name end end |
#logger(kind = :application) ⇒ Object
70 71 72 |
# File 'lib/rgtk/app.rb', line 70 def logger(kind = :application) @loggers[kind] ||= Logger.new(File.open(data_file("#{kind}.log"), 'a')) end |
#root ⇒ Object
16 17 18 |
# File 'lib/rgtk/app.rb', line 16 def root Rgtk.root end |
#run ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rgtk/app.rb', line 24 def run Gtk.init load_models load_controllers if defined?(:MainController) @controllers[:main] = MainController.new @controllers[:main].run end Gtk.main end |