Class: Trinidad::Sandbox::ApplicationContext

Inherits:
Tomcat::Context
  • Object
show all
Extended by:
Helpers::Context
Defined in:
lib/trinidad_sandbox_extension/app/model/application_context.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Context

available_context?, context_not_found, enable_default?, host, invalid_app_path, readonly?, redirect_to_home, render_readonly, repo_not_found, respond_to_invalid_deploy, sandbox_context, warning

Constructor Details

#initialize(context) ⇒ ApplicationContext

Returns a new instance of ApplicationContext.



65
66
67
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 65

def initialize(context)
  super(context)
end

Class Method Details

.allObject



12
13
14
15
16
17
18
19
20
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 12

def self.all
  apps = host ? host.find_children : []
  a = apps.select {|app| app.name != sandbox_context.name }.
    map {|app| ApplicationContext.new(app) }.
    sort {|app1, app2| app1.slug <=> app2.slug }

  a = a.select {|app| app.name != 'default'} unless enable_default?
  a
end

.create(url, path) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 38

def self.create(url, path)
  web_app = Trinidad::WebApp.create({
    :jruby_min_runtimes => 1,
    :jruby_max_runtimes => 1
  }, {
    :context_path => (url == 'default' ? '' : "/#{url}"),
    :web_app_dir => File.basename(path),
    :environment => 'production'
  })

  context = Trinidad::Tomcat::StandardContext.new
  context.path = web_app.context_path
  context.doc_base = web_app.web_app_dir

  context.add_lifecycle_listener Trinidad::Tomcat::Tomcat::DefaultWebXmlListener.new

  config = Trinidad::Tomcat::ContextConfig.new
  config.default_web_xml = 'org/apache/catalin/startup/NO_DEFAULT_XML'
  context.add_lifecycle_listener config

  context.add_lifecycle_listener Trinidad::Lifecycle::Default.new(web_app)

  host.add_child context

  ApplicationContext.new(context)
end

.find(name) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 22

def self.find(name)
  escaped_name = ''
  unless name == 'default'
    escaped_name = '/' + name unless name[0..1] == '/'
  end
  path = CGI.unescape(escaped_name)
  context = host.findChild(path)
  ApplicationContext.new(context) if context
end

.find_by_doc_base(base) ⇒ Object



32
33
34
35
36
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 32

def self.find_by_doc_base(base)
  if (apps = host.find_children)
    apps.select {|app| app.doc_base == File.basename(base)}.first
  end
end

Instance Method Details

#actionsObject



85
86
87
88
89
90
91
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 85

def actions
  [
    {:rel => 'start', :href => "#{self_path}/start"},
    {:rel => 'stop', :href => "#{self_path}/stop"},
    {:rel => 'restart', :href => "#{self_path}/restart"}
  ]
end

#nameObject



73
74
75
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 73

def name
  @name ||= super.empty? ? 'default' : super
end

#parametersObject



93
94
95
96
97
98
99
100
101
102
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 93

def parameters
  @parameters ||= begin
    parameters = {}
    find_parameters.each do |param|
      value = find_parameter(param)
      parameters[param] = value if !value.nil? && !value.empty?
    end
    parameters
  end
end

#pathObject



77
78
79
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 77

def path
  @path ||= super.empty? ? '/' : super
end

#self_pathObject



81
82
83
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 81

def self_path
  @self_path ||= "#{ApplicationContext.sandbox_context.path}/apps/#{slug}"
end

#slugObject



69
70
71
# File 'lib/trinidad_sandbox_extension/app/model/application_context.rb', line 69

def slug
  @slug ||= CGI.escape(name.sub('/', ''))
end