module Incline::Extensions::Application

Adds some informational methods to the Application class.

Public Instance Methods

app_company() click to toggle source

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
app_info() click to toggle source

Gets the application name and version.

# File lib/incline/extensions/application.rb, line 87
def app_info
  "#{app_name} v#{app_version}"
end
app_instance_name() click to toggle source

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
app_name() click to toggle source

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
app_version() click to toggle source

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
request_restart!() click to toggle source

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
restart_pending?() click to toggle source

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
running?() click to toggle source

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

default_notify(property) click to toggle source
# 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
restart_file() click to toggle source
# File lib/incline/extensions/application.rb, line 135
def restart_file
  @restart_file ||= "#{self.config.root}/tmp/restart.txt"
end