Class: OMF::SFA::AM::Runner

Inherits:
Thin::Runner
  • Object
show all
Defined in:
lib/omf-sfa/am/am_runner.rb

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, opts = {}) ⇒ Runner

Returns a new instance of Runner.



23
24
25
26
27
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
# File 'lib/omf-sfa/am/am_runner.rb', line 23

def initialize(argv, opts = {})
  raise "SINGLETON" if @@instance

  @argv = argv
  sopts = opts.delete(:ssl) # runner has it's own idea of ssl options

  # Default options values
  @options = {
    :chdir                => Dir.pwd,
    :environment          => 'development',
    :address              => '0.0.0.0',
    :port                 => Thin::Server::DEFAULT_PORT,
    :timeout              => Thin::Server::DEFAULT_TIMEOUT,
    :log                  => 'log/thin.log',
    :pid                  => 'tmp/pids/thin.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
  }.merge(opts)

  print_options = false
  p = parser
  p.separator ""
  p.separator "Datamapper options:"
  p.on("--dm-db URL", "Datamapper database [#{@options[:dm_db]}]") do |u| @options[:dm_db] = u end
  p.on("--dm-log FILE", "Datamapper log file [#{@options[:dm_log]}]") do |n| @options[:dm_log] = n end
  p.on("--dm-auto-upgrade", "Run Datamapper's auto upgrade") do |n| @options[:dm_auto_upgrade] = true end
  p.separator ""
  p.separator "Testing options:"
  p.on("--test-load-am", "Load an AM configuration for testing") do |n| @options[:load_test_am] = true end
  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 ""
  p.separator "Common options:"

  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

  if print_options
    require 'pp'
    pp @options
  end

  @@instance = self
end

Class Method Details

.instanceObject



19
20
21
# File 'lib/omf-sfa/am/am_runner.rb', line 19

def self.instance
  @@instance
end

Instance Method Details

#init_data_mapperObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/omf-sfa/am/am_runner.rb', line 76

def init_data_mapper

  # Configure the data store
  #
  #DataMapper::Logger.new(@options[:dm_log] || $stdout, :debug)
  DataMapper::Logger.new($stdout, :info)
  #DataMapper::Logger.new(STDOUT, :debug)

  #DataMapper.setup(:default, config[:data_mapper] || {:adapter => 'yaml', :path => '/tmp/am_test2'})
  DataMapper.setup(:default, @options[:dm_db])

  require 'omf-sfa/resource'
  DataMapper::Model.raise_on_save_failure = true
  DataMapper.finalize

  # require  'dm-migrations'
  # DataMapper.auto_migrate!

  DataMapper.auto_upgrade! if @options[:dm_auto_upgrade]

  load_test_am if @options[:load_test_am]

end

#run!Object



100
101
102
103
# File 'lib/omf-sfa/am/am_runner.rb', line 100

def run!
  init_data_mapper
  super
end