shotgun.rb 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. require 'rack'
  2. module Shotgun
  3. autoload :Loader, 'shotgun/loader'
  4. autoload :SkipFavicon, 'shotgun/favicon'
  5. autoload :Static, 'shotgun/static'
  6. def self.new(rackup_file, &block)
  7. Loader.new(rackup_file, &block)
  8. end
  9. def self.enable_copy_on_write
  10. GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
  11. end
  12. def self.preload(files=%w[./config/shotgun.rb ./shotgun.rb])
  13. files.each do |preload_file|
  14. if File.exist?(preload_file)
  15. module_eval File.read(preload_file), preload_file
  16. return preload_file
  17. end
  18. end
  19. end
  20. def self.before_fork(&block)
  21. @before_fork ||= []
  22. @before_fork << block if block
  23. @before_fork
  24. end
  25. def self.after_fork(&block)
  26. @after_fork ||= []
  27. @after_fork << block if block
  28. @after_fork
  29. end
  30. def self.before_fork!
  31. before_fork.each { |block| block.call }
  32. end
  33. def self.after_fork!
  34. after_fork.each { |block| block.call }
  35. end
  36. end