Class: Mentawai::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/mentawai/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Application

Returns a new instance of Application.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mentawai/application.rb', line 8

def initialize(params)
  
  @appContext = Hash.new
  
  @contextPath = params[:app_context] || '/'
  
  @appManagerFilename = params[:app_manager_file] || 'app_manager.rb'
  @appManagerFilename = ".#{contextPathDir}/WEB-INF/#{@appManagerFilename.sub(/^\//, "")}"
  raise "Application manager does not exist: " + @appManagerFilename if not File.exists?(@appManagerFilename)
  
  @appManagerClass = params[:app_manager_class] || 'AppManager'
  
  @appManagerFile = File.new(@appManagerFilename)
  
  @appManager = nil
  
  @extension = params[:action_extension] || 'mtw'
  
  @default_page = params[:default_page] || 'index.erb'
  
  @listing_allowed = params[:listing_allowed] || false
  
  @dirs_allowed_for_listing = params[:dirs_allowed_for_listing] || []
  
  @appManagerFileLastModified = 0
  
end

Instance Attribute Details

#appContextObject (readonly)

Returns the value of attribute appContext.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def appContext
  @appContext
end

#appManagerObject (readonly)

Returns the value of attribute appManager.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def appManager
  @appManager
end

#appManagerClassObject (readonly)

Returns the value of attribute appManagerClass.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def appManagerClass
  @appManagerClass
end

#appManagerFileObject (readonly)

Returns the value of attribute appManagerFile.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def appManagerFile
  @appManagerFile
end

#appManagerFilenameObject (readonly)

Returns the value of attribute appManagerFilename.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def appManagerFilename
  @appManagerFilename
end

#contextPathObject (readonly)

Returns the value of attribute contextPath.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def contextPath
  @contextPath
end

#default_pageObject (readonly)

Returns the value of attribute default_page.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def default_page
  @default_page
end

#dirs_allowed_for_listingObject (readonly)

Returns the value of attribute dirs_allowed_for_listing.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def dirs_allowed_for_listing
  @dirs_allowed_for_listing
end

#extensionObject (readonly)

Returns the value of attribute extension.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def extension
  @extension
end

#listing_allowedObject (readonly)

Returns the value of attribute listing_allowed.



6
7
8
# File 'lib/mentawai/application.rb', line 6

def listing_allowed
  @listing_allowed
end

Instance Method Details

#contextPathDirObject



36
37
38
39
40
41
42
# File 'lib/mentawai/application.rb', line 36

def contextPathDir
  if contextPath == '/'
    "/ROOT"
  else
    contextPath
  end
end

#reloadAppManager(force = false) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mentawai/application.rb', line 48

def reloadAppManager(force = false)
  if force || @appManagerFile.mtime != @appManagerFileLastModified then
    if @appManagerFileLastModified == 0 then
      puts "Loading app manager: " + @appManagerFilename
    else
      puts "Reloading app manager: " + @appManagerFilename
    end
    load @appManagerFilename
    @appManager = eval(appManagerClass + ".new(self)")
    @appManager.init(@appContext)
    @appManagerFileLastModified = @appManagerFile.mtime
  end
end

#to_sObject



44
45
46
# File 'lib/mentawai/application.rb', line 44

def to_s
  "#{contextPath} (#{appManagerFilename}/#{appManagerClass})"
end