Class: OMF::Web::Runner
- Inherits:
-
Thin::Runner
- Object
- Thin::Runner
- OMF::Web::Runner
- Includes:
- Base::Loggable
- Defined in:
- lib/omf-web/thin/runner.rb
Constant Summary collapse
- @@instance =
nil
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, opts = {}) ⇒ Runner
constructor
A new instance of Runner.
- #life_cycle(step, &exception_block) ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(argv, opts = {}) ⇒ Runner
Returns a new instance of Runner.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/omf-web/thin/runner.rb', line 28 def initialize(argv, opts = {}) raise "SINGLETON" if @@instance @@instance = self @argv = argv sopts = opts.delete(:ssl) # runner has it's own idea of ssl options # Default options values app_name = opts[:app_name] || 'omf_web_app' @options = { :app_name => app_name, :chdir => Dir.pwd, :environment => 'development', :address => '0.0.0.0', :port => Thin::Server::DEFAULT_PORT, :timeout => Thin::Server::DEFAULT_TIMEOUT, :log => "/tmp/#{app_name}_thin.log", :pid => "/tmp/#{app_name}.pid", :max_conns => Thin::Server::DEFAULT_MAXIMUM_CONNECTIONS, :max_persistent_conns => Thin::Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS, :require => [], :wait => Thin::Controllers::Cluster::DEFAULT_WAIT_TIME, :rackup => File.dirname(__FILE__) + '/../config.ru', :static_dirs => ["#{File.dirname(__FILE__)}/../../../share/htdocs"], :static_dirs_pre => ["./resources"], # directories to prepend to 'static_dirs' :handlers => {} # procs to call at various times of the server's life cycle }.merge(opts) # Search path for resource files is concatination of 'pre' and 'standard' static dirs @options[:static_dirs] = @options[:static_dirs_pre].concat(@options[:static_dirs]) = false p = parser p.separator "" p.separator "OMF Web options:" p.on("--theme THEME", "Select web theme") do |t| OMF::Web::Theme.theme = t end # Allow application to add it's own parsing options if ph = @options[:handlers][:pre_parse] ph.arity == 1 ? ph.call(p) : ph.call(p, self) end p.separator "" p.separator "Testing options:" p.on("--disable-https", "Run server without SSL") do sopts = nil end p.on("--print-options", "Print option settings after parsing command lines args") do = true end p.separator "" parse! if sopts @options[:ssl] = true @options[:ssl_key_file] ||= sopts[:key_file] @options[:ssl_cert_file] ||= sopts[:cert_file] @options[:ssl_verify] ||= sopts[:verify_peer] end life_cycle(:post_parse) # Change the name of the root logger so we can apply different logging # policies depending on environment. # OMF::Base::Loggable.set_environment @options[:environment] if css = opts[:include_css] require 'omf-web/theme' OMF::Web::Theme.include_css(css) end if require 'pp' pp @options end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/omf-web/thin/runner.rb', line 26 def @options end |
Class Method Details
.instance ⇒ Object
22 23 24 |
# File 'lib/omf-web/thin/runner.rb', line 22 def self.instance @@instance end |
Instance Method Details
#life_cycle(step, &exception_block) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/omf-web/thin/runner.rb', line 106 def life_cycle(step, &exception_block) begin if (p = @options[:handlers][step]) p.arity == 0 ? p.call() : p.call(self) end rescue => ex if exception_block begin exception_block.call(ex) rescue => ex2 error ex2 debug "#{ex2.backtrace.join("\n")}" end else error ex debug "#{ex.backtrace.join("\n")}" end end end |