Module: Trinidad::Sandbox::Helpers::Context

Included in:
ApplicationContext
Defined in:
lib/trinidad_sandbox_extension/app/helpers/context.rb

Instance Method Summary collapse

Instance Method Details

#available_context?(context) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 61

def available_context?(context)
  context.name != sandbox_context.name || enable_default? ||
    (!enable_default? && context.name == 'default')
end

#context_not_found(name) ⇒ Object



22
23
24
25
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 22

def context_not_found(name)
  warning "It seems the application #{name} is not running on Trinidad"
  redirect_to_home 404
end

#enable_default?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 9

def enable_default?
  !!$servlet_context.getAttribute('enable_default')
end

#hostObject



37
38
39
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 37

def host
  $servlet_context.getAttribute('tomcat_host')
end

#invalid_app_path(path) ⇒ Object



32
33
34
35
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 32

def invalid_app_path(path)
  warning "The path #{path} is not valid, please remove the slashes", :now
  respond_to_invalid_deploy
end

#readonly?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 13

def readonly?
  !!$servlet_context.get_attribute('readonly')
end

#redirect_to_home(status_code) ⇒ Object



41
42
43
44
45
46
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 41

def redirect_to_home(status_code)
  respond_to do |wants|
    wants.html { redirect sandbox_context.path }
    wants.xml { status status_code }
  end
end

#render_readonlyObject



17
18
19
20
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 17

def render_readonly
  warning "The console has been started as READONLY, you can access to that resource"
  redirect_to_home 401
end

#repo_not_foundObject



27
28
29
30
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 27

def repo_not_found
  warning "The repository url is required to clone the application", :now
  respond_to_invalid_deploy
end

#respond_to_invalid_deployObject



48
49
50
51
52
53
54
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 48

def respond_to_invalid_deploy
  @page_id = 'deploy'
  respond_to do |wants|
    wants.html { haml :deploy }
    wants.xml { status 400 }
  end
end

#sandbox_contextObject



5
6
7
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 5

def sandbox_context
  @sandbox_context ||= $servlet_context.getAttribute('sandbox_context')
end

#warning(message, req = :next) ⇒ Object



56
57
58
59
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 56

def warning(message, req = :next)
  flash.send(req)[:warning] = message
  $servlet_context.log message
end