Module: Sinatra

Extended by:
Sinatra
Included in:
Sinatra
Defined in:
lib/codebutler/sinatra.rb

Defined Under Namespace

Modules: Builder, Environment, Erb, Haml, RenderingHelpers, ResponseHelpers, Streaming, Version Classes: Application, Error, Event, EventContext, NotFound, Result, ServerError, Static

Instance Method Summary collapse

Instance Method Details

#applicationObject



98
99
100
101
102
103
104
# File 'lib/codebutler/sinatra.rb', line 98

def application
  unless @app 
    @app = Application.new
    Sinatra::Environment.setup!
  end
  @app
end

#application=(app) ⇒ Object



106
107
108
# File 'lib/codebutler/sinatra.rb', line 106

def application=(app)
  @app = app
end

#build_applicationObject



118
119
120
# File 'lib/codebutler/sinatra.rb', line 118

def build_application
  Rack::CommonLogger.new(application)
end

#envObject



114
115
116
# File 'lib/codebutler/sinatra.rb', line 114

def env
  application.options.env
end

#optionsObject



94
95
96
# File 'lib/codebutler/sinatra.rb', line 94

def options
  application.options
end

#portObject



110
111
112
# File 'lib/codebutler/sinatra.rb', line 110

def port
  application.options.port
end

#runObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/codebutler/sinatra.rb', line 122

def run
  
  begin
    puts "== Sinatra has taken the stage on port #{port} for #{env}"
    require 'pp'
    Rack::Handler::Mongrel.run(build_application, :Port => port) do |server|
      trap(:INT) do
        server.stop
        puts "\n== Sinatra has ended his set (crowd applauds)"
      end
    end
  rescue Errno::EADDRINUSE => e
    puts "== Someone is already performing on port #{port}!"
  end
  
end