module Trinidad::Extensions

Public Class Methods

configure_options_extensions(extensions, parser, default_options) click to toggle source
# File lib/trinidad/extensions.rb, line 4
def self.configure_options_extensions(extensions, parser, default_options)
  extensions.each do |name, options|
    if extension = extension(name, 'OptionsExtension', options)
      extension.configure(parser, default_options)
    end
  end if extensions
end
configure_server_extensions(extensions, tomcat) click to toggle source
# File lib/trinidad/extensions.rb, line 12
def self.configure_server_extensions(extensions, tomcat)
  extensions.each do |name, options|
    if extension = extension(name, 'ServerExtension', options)
      outcome = extension.configure(tomcat)
      if tomcat_like?(outcome) || extension.override_tomcat?
        tomcat = outcome
      end
    end
  end if extensions
  tomcat
end
configure_webapp_extensions(extensions, tomcat, context) click to toggle source
# File lib/trinidad/extensions.rb, line 24
def self.configure_webapp_extensions(extensions, tomcat, context)
  extensions.each do |name, options|
    if extension = extension(name, 'WebAppExtension', options)
      extension.tomcat = tomcat
      if extension.method(:configure).arity == 2
        extension.configure(tomcat, context) # #deprecated old way
      else
        extension.configure(context)
      end
    end
  end if extensions
end

Protected Class Methods

extension(name, type, options) click to toggle source
# File lib/trinidad/extensions.rb, line 39
def self.extension(name, type, options)
  class_name = Helpers.camelize(name) << type; clazz = nil
  if ( const_defined?(class_name) rescue nil )
    clazz = const_get(class_name)
  else
    begin
      load_extension(name)
    rescue LoadError => e
      Helpers.warn("Failed to load the #{name.inspect} extension (#{e.message}) ")
    else
      clazz = ( const_get(class_name) if const_defined?(class_name) ) rescue nil
    end
  end
  clazz.new(options) if clazz # MyExtension.new(options)
end
load_extension(name) click to toggle source
# File lib/trinidad/extensions.rb, line 55
def self.load_extension(name)
  require "trinidad_#{name}_extension"
end

Private Class Methods

camelize(string) click to toggle source
# File lib/trinidad/extensions.rb, line 65
def self.camelize(string)
  Helpers.deprecate("Trinidad::Extensions.camelize use the camelize helper " << 
                    "available in your Extension")
  Helpers.camelize(string)
end
tomcat_like?(tomcat) click to toggle source
# File lib/trinidad/extensions.rb, line 61
def self.tomcat_like?(tomcat)
  tomcat.respond_to?(:server) && tomcat.respond_to?(:start) && tomcat.respond_to?(:stop)
end