class TingYun::Support::LocalEnvironment
Public Class Methods
find_class_in_object_space(klass)
click to toggle source
Runs through all the objects in ObjectSpace to find the first one that match the provided class
# File lib/ting_yun/support/local_environment.rb, line 26 def self.find_class_in_object_space(klass) if TingYun::Support::LanguageSupport.object_space_usable? ObjectSpace.each_object(klass) do |x| return x end end return nil end
new()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 13 def initialize # Extend self with any any submodules of LocalEnvironment. These can override # the discover methods to discover new framworks and dispatchers. TingYun::Support::LocalEnvironment.constants.each do | const | mod = TingYun::Support::LocalEnvironment.const_get const self.extend mod if mod.instance_of? Module end @discovered_dispatcher = nil discover_dispatcher end
Public Instance Methods
discovered_dispatcher()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 8 def discovered_dispatcher discover_dispatcher unless @discovered_dispatcher @discovered_dispatcher end
executable()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 180 def executable File.basename($0) end
to_s()
click to toggle source
outputs a human-readable description
# File lib/ting_yun/support/local_environment.rb, line 174 def to_s s = "LocalEnvironment[" s << ";dispatcher=#{@discovered_dispatcher}" if @discovered_dispatcher s << "]" end
Private Instance Methods
check_for_delayed_job()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 121 def check_for_delayed_job if $0 =~ /delayed_job$/ || (File.basename($0) == 'rake' && ARGV.include?('jobs:work')) @discovered_dispatcher = :delayed_job end end
check_for_fastcgi()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 90 def check_for_fastcgi return unless defined?(::FCGI) @discovered_dispatcher = :fastcgi end
check_for_glassfish()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 68 def check_for_glassfish return unless defined?(::JRuby) && (((com.sun.grizzly.jruby.rack.DefaultRackApplicationFactory rescue nil) && defined?(com::sun::grizzly::jruby::rack::DefaultRackApplicationFactory)) || (jruby_rack? && defined?(::GlassFish::Server))) @discovered_dispatcher = :glassfish end
check_for_litespeed()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 160 def check_for_litespeed if caller.pop =~ /fcgi-bin\/RailsRunner\.rb/ @discovered_dispatcher = :litespeed end end
check_for_mongrel()
click to toggle source
this case covers starting by mongrel_rails
# File lib/ting_yun/support/local_environment.rb, line 96 def check_for_mongrel return unless defined?(::Mongrel) && defined?(::Mongrel::HttpServer) @discovered_dispatcher = :mongrel end
check_for_passenger()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 166 def check_for_passenger if defined?(::PhusionPassenger) @discovered_dispatcher = :passenger end end
check_for_puma()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 115 def check_for_puma if defined?(::Puma) && $0.include?('puma') @discovered_dispatcher = :puma end end
check_for_rainbows()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 108 def check_for_rainbows if (defined?(::Rainbows) && defined?(::Rainbows::HttpServer)) && TingYun::Support::LanguageSupport.object_space_usable? _v = TingYun::Support::LocalEnvironment.find_class_in_object_space(::Rainbows::HttpServer) @discovered_dispatcher = :rainbows if _v end end
check_for_resque()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 127 def check_for_resque has_queue = ENV['QUEUE'] || ENV['QUEUES'] resque_rake = executable == 'rake' && ARGV.include?('resque:work') resque_pool_rake = executable == 'rake' && ARGV.include?('resque:pool') resque_pool_executable = executable == 'resque-pool' && defined?(::Resque::Pool) using_resque = defined?(::Resque) && (has_queue && resque_rake) || (resque_pool_executable || resque_pool_rake) @discovered_dispatcher = :resque if using_resque end
check_for_sidekiq()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 140 def check_for_sidekiq if defined?(::Sidekiq) && File.basename($0) == 'sidekiq' @discovered_dispatcher = :sidekiq end end
check_for_thin()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 146 def check_for_thin if defined?(::Thin) && defined?(::Thin::Server) # If ObjectSpace is available, use it to search for a Thin::Server # instance. Otherwise, just the presence of the constant is sufficient. if TingYun::Support::LanguageSupport.object_space_usable? ObjectSpace.each_object(Thin::Server) do |thin_dispatcher| @discovered_dispatcher = :thin end else @discovered_dispatcher = :thin end end end
check_for_torquebox()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 62 def check_for_torquebox return unless defined?(::JRuby) && ( org.torquebox::TorqueBox rescue nil) @discovered_dispatcher = :torquebox end
check_for_trinidad()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 76 def check_for_trinidad return unless defined?(::JRuby) && jruby_rack? && defined?(::Trinidad::Server) @discovered_dispatcher = :trinidad end
check_for_unicorn()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 101 def check_for_unicorn if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer)) && TingYun::Support::LanguageSupport.object_space_usable? _v = TingYun::Support::LocalEnvironment.find_class_in_object_space(::Unicorn::HttpServer) @discovered_dispatcher = :unicorn if _v end end
check_for_webrick()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 85 def check_for_webrick return unless defined?(::WEBrick) && defined?(::WEBrick::VERSION) @discovered_dispatcher = :webrick end
discover_dispatcher()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 38 def discover_dispatcher dispatchers = %w[ passenger torquebox trinidad glassfish resque sidekiq delayed_job puma thin mongrel litespeed webrick fastcgi rainbows unicorn ] while dispatchers.any? && !@discovered_dispatcher send 'check_for_'+(dispatchers.shift) end end
jruby_rack?()
click to toggle source
# File lib/ting_yun/support/local_environment.rb, line 81 def jruby_rack? defined?(JRuby::Rack::VERSION) end