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

This method returns instantiated modules of all valid applications in an Array or in a block.



28
29
30
31
32
33
34
35
36
37
# File 'lib/csd/applications.rb', line 28

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

.currentObject

This method holds the desired application and initializes its module into @@current.



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

def self.current
  # In testmode we don't want to perform caching
  return choose_current if Options.testmode
  # Otherwise we choose and cache the current application module here
  @@current ||= choose_current
end

.find(app_name) ⇒ Object

Returns the application module instance of app_name. Returns nil if the application could not be found or loaded.



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

def self.find(app_name)
  return nil if app_name.to_s.empty?
  begin
    UI.debug "#{self}.find got a request to see whether `#{app_name}´ is a valid application or not"
    require File.join(Path.applications, app_name.to_s)
    UI.debug "#{self}.find tries to initialize the loaded application `#{app_name}´ now"
    "CSD::Application::#{app_name.to_s.camelize}".constantize
  rescue LoadError => e
    UI.debug "#{self}.find could not load `#{app_name}´ in #{e.to_s.gsub('no such file to load -- ', '').enquote}"
    nil
  end
end