class MediTAF::UI::Applications

Manages all of the applications in the applications root directory

Attributes

apps[R]
apps_root[R]
current_app[R]

Public Class Methods

new(apps_root) click to toggle source

@param apps_root [String] root location of applications with their defined pages

# File lib/MediTAF/ui/applications.rb, line 16
def initialize(apps_root)
  @apps = {}
  @apps_root = apps_root
end

Public Instance Methods

close() click to toggle source

only empties the applications internal apps collection

# File lib/MediTAF/ui/applications.rb, line 22
def close
  @apps.clear
end
each(&block) click to toggle source

iterates over the loaded applications collection @param block [Proc]

# File lib/MediTAF/ui/applications.rb, line 35
def each(&block)
  @apps.each(&block) if @apps
end
method_missing(app, *args, &block) click to toggle source

references an application as a method name @param app [Symbol] the application name as a symbol @return [Application] the current application

# File lib/MediTAF/ui/applications.rb, line 29
def method_missing(app, *args, &block)
  @current_app = @apps.include?(app) ? @apps[app] : load_app(app)
end

Private Instance Methods

load_app(app) click to toggle source

@param app [Symbol] the application name as a symbol @return [Application] the newly accessed application @raise [AppLoadError] when manager cannot fully load the requested app

# File lib/MediTAF/ui/applications.rb, line 49
def load_app(app)
  raise "Directory #{@apps_root}/#{app} not found" unless Dir["#{@apps_root}/*"].detect do |f|
    File.directory?(f) && File.basename(f).downcase.to_sym == app
  end
  new_app = Application.new("#{@apps_root}/#{app.to_s.downcase}")
  @apps[app] = new_app
rescue => e
  raise AppLoadError, "Couldn't load #{app}. Inner Exception: #{e.to_s}"
end