Class: CSD::Applications

Inherits:
Object show all
Defined in:
lib/csd/applications.rb

Overview

A convenience wrapper to get information about the available applications

Class Method Summary collapse

Class Method Details

.all(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/csd/applications.rb', line 23

def self.all(&block)
  result = []
  Dir.directories(Path.applications) do |dir|
    next if dir == 'default'
    if app = find(dir)
      block_given? ? yield(app) : result << app
    end
  end
  result
end

.currentObject

This method identifies the desired application and initializes it in to @@current. It is meant to be very robust, we expect the application to be any one of the first three arguments.



41
42
43
44
45
# File 'lib/csd/applications.rb', line 41

def self.current
  @@current ||= begin
    Applications.find(ARGV.first) || Applications.find(ARGV.second) || Applications.find(ARGV.third)
  end
end

.current!Object

Forces a reload of the current application. This method is useful for functional tests.



49
50
51
52
# File 'lib/csd/applications.rb', line 49

def self.current!
  @@current = false
  current
end

.find(app_name) ⇒ Object

Returns nil if application could not be found



13
14
15
16
17
18
19
20
21
# File 'lib/csd/applications.rb', line 13

def self.find(app_name)
  begin
    require File.join(Path.applications, app_name.to_s)
    ActiveSupport::Inflector.constantize "CSD::Application::#{app_name.camelize}"
  rescue LoadError
    UI.debug "The Application `#{app_name}´ could not be loaded properly."
    nil
  end
end

.valid?(name) ⇒ Boolean

Returns:



34
35
36
# File 'lib/csd/applications.rb', line 34

def self.valid?(name)
  list.include?(name)
end