Class: Editserver::Command
- Inherits:
-
Object
- Object
- Editserver::Command
- Defined in:
- lib/editserver/command.rb
Instance Method Summary collapse
-
#editoropts ⇒ Object
returns dup of @editoropts merged with rcopts.
-
#initialize(args = []) ⇒ Command
constructor
A new instance of Command.
- #options ⇒ Object
-
#rackopts ⇒ Object
returns dup of @rackopts masked by rcopts.
- #rcopts ⇒ Object
- #run ⇒ Object
- #server ⇒ Object
Constructor Details
#initialize(args = []) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/editserver/command.rb', line 9 def initialize args = [] @args = args @opts = { :rcfile => "~/.editserverrc" } # keys are strings because YAML.load returns string keys, # and we are not restricting the keys like @rackopts @editoropts = { 'default' => nil, 'terminal' => nil } @rackopts = { :Host => '127.0.0.1', :Port => 9999, :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), # be less chatty :AccessLog => [], # rack does its own access logging, so keep this blank :pid => nil, :config => '', :environment => 'deployment' } end |
Instance Method Details
#editoropts ⇒ Object
returns dup of @editoropts merged with rcopts
92 93 94 |
# File 'lib/editserver/command.rb', line 92 def editoropts @editoropts.dup.merge rcopts['editor'] end |
#options ⇒ Object
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 |
# File 'lib/editserver/command.rb', line 31 def OptionParser.new do |opt| opt.summary_width = 20 opt. = %Q(\ Usage: #{File.basename $0} [options] Options: ).gsub /^ +/, '' opt.on '-p', '--port NUMBER', Integer, "default: #{rackopts[:Port]}" do |arg| @rackopts[:Port] = arg end opt.on '-t', '--terminal CMD', 'Terminal to launch for console editors' do |arg| @editoropts['terminal'] = arg end opt.on '--rc PATH', "Path to rc file; #{@opts[:rcfile]} by default", '(Also can be set by exporting EDITSERVERRC to environment)' do |arg| @rcopts = nil # reset cached user opts @opts[:rcfile] = File. arg end opt.on '--no-rc', 'Suppress reading of rc file' do @opts[:norcfile] = true end end end |
#rackopts ⇒ Object
returns dup of @rackopts masked by rcopts
81 82 83 84 85 86 87 88 89 |
# File 'lib/editserver/command.rb', line 81 def rackopts (opts = @rackopts.dup).keys.each do |k| v = rcopts['rack'][k.to_s] v = rcopts['rack'][k.to_s.downcase] if v.nil? # be tolerant of lowercase keys opts[k] = v unless v.nil? end opts end |
#rcopts ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/editserver/command.rb', line 61 def rcopts @rcopts ||= begin empty = { 'rack' => {}, 'editor' => {} } rcfile = File. ENV['EDITSERVERRC'] || @opts[:rcfile] if @opts[:norcfile] empty elsif File.exists? rcfile opts = YAML.load_file File.(rcfile) opts ||= {} opts['rack'] ||= {} opts['editor'] ||= {} opts else empty end end end |
#run ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/editserver/command.rb', line 104 def run .parse @args begin $0 = 'editserver' puts server.start ensure puts fx("\nGoodbye!", [32,1]) end end |
#server ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/editserver/command.rb', line 96 def server # HACK: Fixed in master -- remove when upgrading min rack dependency # http://groups.google.com/group/rack-devel/browse_thread/thread/8f6c3b79c99809ee srv = Rack::Server.new rackopts srv.instance_variable_set :@app, Editserver.new(editoropts) srv end |