Module: Sinatra::AppModule

Defined in:
lib/sinatra/support/appmodule.rb

Overview

Allows you to write parts of an application as a module.

Usage

require 'sinatra/support'
# or require 'sinatra/support/appmodule'

Create a part of your application by placing the usual Sinatra directives (@@get@@, @@helpers@@, @@configure@@, etc) in a module. Be sure to @@include Sinatra::AppModule@@ first.

module LoginModule
  include Sinatra::AppModule

  helpers do
    def logged_in?
      # ...
    end
  end

  get '/login' do
    # ...
  end
end

In your Sinatra application, simply include the module to bring those routes and helpers in.

class MyApplication < Sinatra::Base
  include LoginModule
end

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



34
35
36
# File 'lib/sinatra/support/appmodule.rb', line 34

def self.included(controller)
  controller.extend ClassMethods
end