module Incline::Extensions::Application
Adds some informational methods to the Application
class.
Public Instance Methods
Gets the company owning the copyright to the application.
You should override this method in your application.rb
file to return the appropriate value.
# File lib/incline/extensions/application.rb, line 72 def app_company default_notify :app_company 'BarkerEST' end
Gets the copyright statement for this application.
# File lib/incline/extensions/application.rb, line 93 def app_copyright(html = true) if html "Copyright © #{CGI::escapeHTML app_copyright_year} #{CGI::escapeHTML app_company}".html_safe else "Copyright (C) #{app_copyright_year} #{app_company}" end end
Gets the year of copyright ownership for the company.
Defaults to the current year (at the time of execution).
# File lib/incline/extensions/application.rb, line 81 def app_copyright_year Time.now.year.to_s end
Gets the application name and version.
# File lib/incline/extensions/application.rb, line 87 def app_info "#{app_name} v#{app_version}" end
Gets the application instance name.
This can be set by creating a config/instance.yml
configuration file and setting the 'name' property. The instance name is used to create unique cookies for each instance of an application. The default instance name is 'default'.
# File lib/incline/extensions/application.rb, line 46 def app_instance_name @app_instance_name ||= begin yaml = Rails.root.join('config','instance.yml') if File.exist?(yaml) yaml = (YAML.load(ERB.new(File.read(yaml)).result) || {}).symbolize_keys yaml[:name].blank? ? 'default' : yaml[:name] else 'default' end end end
Gets the application name.
You should override this method in your application.rb
file to return the appropriate value.
# File lib/incline/extensions/application.rb, line 35 def app_name default_notify :app_name 'Incline' end
Gets the application version.
You should override this method in your application.rb
file to return the appropriate value.
# File lib/incline/extensions/application.rb, line 63 def app_version default_notify :app_version '0.0.1' end
Updates the restart file to indicate we want to restart the web app.
# File lib/incline/extensions/application.rb, line 111 def request_restart! Incline::Log::info 'Requesting an application restart.' FileUtils.touch restart_file File.mtime restart_file end
Is a restart currently pending.
# File lib/incline/extensions/application.rb, line 103 def restart_pending? return false unless File.exist?(restart_file) request_time = File.mtime(restart_file) request_time > Incline.start_time end
Is the rails server running?
# File lib/incline/extensions/application.rb, line 14 def running? path = File.join(Rails.root, 'tmp/pids/server.pid') pid = File.exist?(path) ? File.read(path).to_i : -1 server_running = true begin if Gem.win_platform? result = `tasklist /FO LIST /FI "PID eq #{pid}"`.strip server_running = !!(result =~ /^PID:\s+#{pid}$/) else Process.getpgid pid end rescue Errno::ESRCH, NotImplementedError server_running = false end server_running end
Private Instance Methods
# File lib/incline/extensions/application.rb, line 126 def default_notify(property) @default_notify ||= {} @default_notify[property] ||= 0 if @default_notify[property] == 0 @default_notify[property] = 1 Incline::Log::warn "Default \"#{property}\" is in use. Please define \"#{property}\" in your \"application.rb\" file." end end
# File lib/incline/extensions/application.rb, line 135 def restart_file @restart_file ||= "#{self.config.root}/tmp/restart.txt" end