Class: Flunkey::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/flunkey/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



44
45
46
# File 'lib/flunkey/application.rb', line 44

def initialize
  self.options = {}
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/flunkey/application.rb', line 7

def options
  @options
end

Class Method Details

.run(args = ARGV) ⇒ Object



40
41
42
# File 'lib/flunkey/application.rb', line 40

def self.run(args = ARGV)
  new.run(args)
end

Instance Method Details

#default_optionsObject



14
15
16
17
18
19
20
21
22
# File 'lib/flunkey/application.rb', line 14

def default_options
  root = File.expand_path('../../', File.dirname(__FILE__))
  {
    root: root,
    port: 8080,
    address: '127.0.0.1',
    paths: [root]
  }
end

#parse(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/flunkey/application.rb', line 24

def parse(args)
  optparse = OptionParser.new do|opts|
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("--version", "Show version") do
      puts Flunkey::VERSION
      exit
    end
  end
  optparse.parse(args)
  options.merge default_options
end

#run(args = ARGV) ⇒ Object



9
10
11
12
# File 'lib/flunkey/application.rb', line 9

def run(args = ARGV)
  @options = parse(args)
  run_server
end

#run_serverObject



48
49
50
# File 'lib/flunkey/application.rb', line 48

def run_server
  Flunkey::Server.run! self.options
end