Class: Mentawai::Core::ApplicationManager

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ApplicationManager

Returns a new instance of ApplicationManager.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mentawai/core/app_manager.rb', line 8

def initialize(app)
  
  puts "Initializing application manager..."
  
  @app = app
  
  @actions = Hash.new
  @innerActions = Hash.new
  
  @globalFilters = Array.new
  @globalConsequences = Hash.new
  
  @loader = Loader.new(".#{app.contextPathDir}/WEB-INF")
  @loader.reloadFiles
  
  @pageMethods = initPageMethods
  @customPageMethods = Hash.new
end

Instance Method Details

#action(params) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mentawai/core/app_manager.rb', line 53

def action(params)
  if params.is_a?(Hash)
    class_name = params[:class_name]; raise "class_name is required!" if not class_name
    action_name = params[:action_name]; action_name.sub!(/^\//, "") if action_name
    inner_action = params[:inner_action]
    ac = ActionConfig.new(class_name, action_name, inner_action)
    addActionConfig(ac)
  elsif params.is_a?(String)
    class_name = params
    ac = ActionConfig.new(class_name)
    addActionConfig(ac)
  else
    raise "Invalid arguments to create action config!"
  end
end

#addActionConfig(ac) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/mentawai/core/app_manager.rb', line 69

def addActionConfig(ac)
  actionName = ac.actionName
  innerAction = ac.innerAction
  if innerAction == nil then
    @actions[actionName] = ac
  else
    map = @innerActions[actionName]
    if map == nil then
      map = Hash.new
      @innerActions[actionName] = map
    end
    map[innerAction] = ac
  end
  ac
end

#addPageMethod(name, *params) ⇒ Object



43
44
45
46
47
# File 'lib/mentawai/core/app_manager.rb', line 43

def addPageMethod(name, *params)
  raise "Invalid parameters!" if params.length == 0 || params.length > 2
  params[1] = 'exec' if params[1].nil?
  @customPageMethods[name] = params
end

#appObject



31
32
33
# File 'lib/mentawai/core/app_manager.rb', line 31

def app
  @app
end

#customPageMethodsObject



49
50
51
# File 'lib/mentawai/core/app_manager.rb', line 49

def customPageMethods
  @customPageMethods
end

#filter(filter) ⇒ Object



85
86
87
# File 'lib/mentawai/core/app_manager.rb', line 85

def filter(filter)
  @globalFilters.push(filter)
end

#filtersObject



89
90
91
92
93
# File 'lib/mentawai/core/app_manager.rb', line 89

def filters
  @globalFilters.each do |f|
    yield f
  end
end

#getActionConfig(actionName, innerAction = nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mentawai/core/app_manager.rb', line 103

def getActionConfig(actionName, innerAction = nil)

  if innerAction == nil then
    @actions[actionName]
  else
    map = @innerActions[actionName]
    if map == nil
      # Use consequences from regular action
      @actions[actionName]
    else
      map[innerAction]
    end
  end
end

#getConsequence(result) ⇒ Object



99
100
101
# File 'lib/mentawai/core/app_manager.rb', line 99

def getConsequence(result)
  @globalConsequences[result]
end

#init(application) ⇒ Object



27
28
29
# File 'lib/mentawai/core/app_manager.rb', line 27

def init(application)
  # should be overriden...
end

#on(result, conseq) ⇒ Object



95
96
97
# File 'lib/mentawai/core/app_manager.rb', line 95

def on(result, conseq)
  @globalConsequences[result] = conseq
end

#pageMethodsObject



35
36
37
# File 'lib/mentawai/core/app_manager.rb', line 35

def pageMethods
  @pageMethods
end

#reloadActionsObject



39
40
41
# File 'lib/mentawai/core/app_manager.rb', line 39

def reloadActions
  @loader.reloadFiles
end