Skip to content

Instantly share code, notes, and snippets.

@mcfiredrill
Last active December 14, 2015 06:18
Show Gist options
  • Save mcfiredrill/5041121 to your computer and use it in GitHub Desktop.
Save mcfiredrill/5041121 to your computer and use it in GitHub Desktop.
modular sinatra app taken from here => https://github.com/jfeaver/modular-sinatra/
class Datafruits < Sinatra::Base
@@my_app = {}
def self.new(*) self < Datafruits ? super : Rack::URLMap.new(@@my_app) end
def self.map(url) @@my_app[url] = self end
# do all config stuff in this file
enable :sessions
use Rack::Flash
class ApplicationController < Datafruits
map '/'
end
class SessionsController < Datafruits
map '/'
end
class UsersController < Datafruits
map '/users'
end
end
class Datafruits
class ApplicationController
get '/'
erb :index
end
end
end
dir = File.expand_path("../", File.dirname(__FILE__))
require "#{dir}/app"
app_dir = File.join("#{app_dir}", "app/")
controller_files = File.join(app_dir, %w(controllers ** *_controller.rb))
model_files = File.join(app_dir, %w(models ** *.rb))
lib_files = File.join(dir, %w(lib ** *))
files = [controller_files, model_files, lib_files]
Dir.glob(files).each {|lf| require lf }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment