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)


65
66
67
68
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 65

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

#context_not_found(name) ⇒ Object



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

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

#git_ssh?Boolean

Returns:

  • (Boolean)


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

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

#hostObject



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

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

#invalid_app_path(path) ⇒ Object



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

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)


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

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

#redirect_to_home(status_code) ⇒ Object



45
46
47
48
49
50
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 45

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



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

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



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

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

#respond_to_invalid_deployObject



52
53
54
55
56
57
58
# File 'lib/trinidad_sandbox_extension/app/helpers/context.rb', line 52

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



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

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