Method: OMF::Web::Runner#initialize

Defined in:
lib/omf-web/thin/runner.rb

#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])



  print_options = 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 print_options = 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 print_options
    require 'pp'
    pp @options
  end

end