Module: Incline::Extensions::Application
- Defined in:
- lib/incline/extensions/application.rb
Overview
Adds some informational methods to the Application class.
Instance Method Summary collapse
-
#app_company ⇒ Object
Gets the company owning the copyright to the application.
-
#app_copyright(html = true) ⇒ Object
Gets the copyright statement for this application.
-
#app_copyright_year ⇒ Object
Gets the year of copyright ownership for the company.
-
#app_info ⇒ Object
Gets the application name and version.
-
#app_instance_name ⇒ Object
Gets the application instance name.
-
#app_name ⇒ Object
Gets the application name.
-
#app_version ⇒ Object
Gets the application version.
-
#cookie_name(cookie) ⇒ Object
Generates a cookie name using the application name and instance name.
-
#request_restart! ⇒ Object
Updates the restart file to indicate we want to restart the web app.
-
#restart_pending? ⇒ Boolean
Is a restart currently pending.
-
#running? ⇒ Boolean
Is the rails server running?.
Instance Method Details
#app_company ⇒ Object
Gets the company owning the copyright to the application.
You should override this method in your application.rb
file to return the appropriate value.
72 73 74 75 |
# File 'lib/incline/extensions/application.rb', line 72 def app_company default_notify :app_company 'BarkerEST' end |
#app_copyright(html = true) ⇒ Object
Gets the copyright statement for this application.
93 94 95 96 97 98 99 |
# 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 |
#app_copyright_year ⇒ Object
Gets the year of copyright ownership for the company.
Defaults to the current year (at the time of execution).
81 82 83 |
# File 'lib/incline/extensions/application.rb', line 81 def app_copyright_year Time.now.year.to_s end |
#app_info ⇒ Object
Gets the application name and version.
87 88 89 |
# File 'lib/incline/extensions/application.rb', line 87 def app_info "#{app_name} v#{app_version}" end |
#app_instance_name ⇒ Object
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’.
46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 |
#app_name ⇒ Object
Gets the application name.
You should override this method in your application.rb
file to return the appropriate value.
35 36 37 38 |
# File 'lib/incline/extensions/application.rb', line 35 def app_name default_notify :app_name 'Incline' end |
#app_version ⇒ Object
Gets the application version.
You should override this method in your application.rb
file to return the appropriate value.
63 64 65 66 |
# File 'lib/incline/extensions/application.rb', line 63 def app_version default_notify :app_version '0.0.1' end |
#cookie_name(cookie) ⇒ Object
Generates a cookie name using the application name and instance name.
119 120 121 |
# File 'lib/incline/extensions/application.rb', line 119 def () "_incline_#{app_name.downcase.scan(/[a-z0-9]+/).join('_')}_#{app_instance_name.downcase.scan(/[a-z0-9]+/).join('_')}_#{}" end |
#request_restart! ⇒ Object
Updates the restart file to indicate we want to restart the web app.
111 112 113 114 115 |
# 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 |
#restart_pending? ⇒ Boolean
Is a restart currently pending.
103 104 105 106 107 |
# 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 |
#running? ⇒ Boolean
Is the rails server running?
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |