Created
May 18, 2010 11:32
-
-
Save peterc/404894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bits and pieces from my large, multi-file Sinatra app.. just to show structure | |
# ----- | |
# Main base Sinatra app setup | |
module Cio | |
class App < Sinatra::Base | |
configure do | |
# Set global vars | |
set :root, APP_ROOT | |
set :environment, ENV['environment'] || environment | |
set :secret, ENV['secret'] | |
# Connect to database | |
MongoMapper.connection = Mongo::Connection.new(hostname) | |
MongoMapper.database = "#{dbname}-#{environment}" | |
end | |
end | |
end | |
# Load plugins, models, controllers, and helpers | |
(Dir[APP_ROOT + "/plugins/*.rb"] + Dir[APP_ROOT + "/app/models/*.rb"] + Dir[APP_ROOT + "/app/controllers/*.rb"]).each { |f| require f; puts f } | |
# Attach helpers and register plugins | |
module Cio | |
class App | |
helpers Cio::Helpers | |
register Sinatra::SessionAuth | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Root level and "controller-less" methods and webapp actions | |
module Cio | |
class App | |
API_PREFIX = "/api/v1" | |
get "#{API_PREFIX}/users/?" do | |
[..] | |
end | |
post "#{API_PREFIX}/users/:id" do | |
[..] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Cio | |
module Helpers | |
[..] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment