Skip to content

Instantly share code, notes, and snippets.

@peterc
Created May 18, 2010 11:32
Show Gist options
  • Save peterc/404894 to your computer and use it in GitHub Desktop.
Save peterc/404894 to your computer and use it in GitHub Desktop.
# 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
# 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
module Cio
module Helpers
[..]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment