Search code examples
rubysinatramodular-design

What is meant by Modular in Sinatra?


I was wondering if someone could simplify the explanation for what Modular is within a Sinatra app. I see that there is the classic setup and a modular setup within sinatra, but from reading the docs I can't quite grasp what Modular is doing.

I would really like an explanation at its basic level if possible and why putting this in profile.rb would change the setup of the app (if that is the case). Please keep in mind that I'm a newbie, so simple and thorough explanations are best!

require 'rubygems'
require 'sinatra'

class Profile < Sinatra::Base

get '/' do
 erb :index
end


end

Solution

  • It means that you can create one or more Sinatra apps like the one you outlined in your question, as independent modules within the same super-app, for instance tied together using Rack#map:

    # config.ru
    
    require 'app1'
    require 'app2'
    
    run Rack::Builder.new {
      map "/app1" do
        run App1.new
      end
    
      map "/app2" do
        run App2.new
      end
    }