Sha256: ea4b6b5c44061c58146153e9ca55cc9760b7d3e92e28735999733c2c11c505ac

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'rubygems'
gem 'trinidad_jars'
require 'trinidad/extensions'
require 'java'

module Trinidad
  module Extensions
    module Lifecycle
      VERSION = '0.2.1'

      def init_listeners(context, path, mod_name)
        path ||= File.join('lib', 'lifecycle')

        Dir.glob("#{path}/*.rb").each do |listener|
          load listener
        end

        mod = constantize(mod_name)
        return unless mod

        mod.constants.each do |listener|
          const_listener = mod.const_get(listener)
          context.add_lifecycle_listener(const_listener.new)
        end
      end

      def constantize(mod)
        names = mod.split('::')
        names.inject(Object) {|constant, obj| constant.const_get(obj) } rescue nil
      end
    end


    class LifecycleServerExtension < ServerExtension
      include Lifecycle

      def configure(tomcat)
        init_listeners(tomcat.server, @options[:path], 'Trinidad::Lifecycle::Server')
      end
    end

    class LifecycleWebAppExtension < WebAppExtension
      include Lifecycle

      def configure(tomcat, app_context)
        init_listeners(app_context, @options[:path], 'Trinidad::Lifecycle::WebApp')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trinidad_lifecycle_extension-0.2.1 lib/trinidad_lifecycle_extension.rb