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.
67 68 69 70 |
# File 'lib/incline/extensions/application.rb', line 67 def app_company default_notify :app_company 'BarkerEST' end |
#app_copyright(html = true) ⇒ Object
Gets the copyright statement for this application.
88 89 90 91 92 93 94 |
# File 'lib/incline/extensions/application.rb', line 88 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).
76 77 78 |
# File 'lib/incline/extensions/application.rb', line 76 def app_copyright_year Time.now.year.to_s end |
#app_info ⇒ Object
Gets the application name and version.
82 83 84 |
# File 'lib/incline/extensions/application.rb', line 82 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’.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/incline/extensions/application.rb', line 41 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.
30 31 32 33 |
# File 'lib/incline/extensions/application.rb', line 30 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.
58 59 60 61 |
# File 'lib/incline/extensions/application.rb', line 58 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.
114 115 116 |
# File 'lib/incline/extensions/application.rb', line 114 def () "_incline_#{app_name.downcase.scan(/[a-z0-9]+/).join('_')}_#{app_instance_name.downcase.scan(/[a-z0-9]+/).join('_')}_#{cookie}" end |
#request_restart! ⇒ Object
Updates the restart file to indicate we want to restart the web app.
106 107 108 109 110 |
# File 'lib/incline/extensions/application.rb', line 106 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.
98 99 100 101 102 |
# File 'lib/incline/extensions/application.rb', line 98 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 |
# 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 Process.getpgid pid rescue Errno::ESRCH server_running = false end server_running end |