Sha256: 48d233f2d00572ed4b7e22686eb3e07a5c316b1a45246b628d50e7f8de9b0e17

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'delegate'
require 'cgi'

require File.expand_path('../../helpers/sandbox', __FILE__)

module Trinidad
  module Sandbox
    class ApplicationContext < DelegateClass(Trinidad::Tomcat::Context)
      extend Trinidad::Sandbox::Helpers::Context

      def self.all
        apps = host ? host.find_children : []
        apps.select {|app| app.name != sandbox_context.name }.
          map {|app| ApplicationContext.new(app) }
      end

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

      def initialize(context)
        super(context)
      end

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

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

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

      def parameters
        @parameters ||= find_parameters
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trinidad_sandbox_extension-0.4.0 lib/trinidad_sandbox_extension/app/model/application_context.rb