Sha256: 4e0320472f49de7c97c93ba2e9382c90310d045f5ec7018f40d04467f1df9829

Contents?: true

Size: 1.09 KB

Versions: 47

Compression:

Stored size: 1.09 KB

Contents

# Allows you to write parts of an application as a module.
#
# == Usage
#
#   require 'sinatra/support/module'
#   
# 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
#
module Sinatra::AppModule
  def self.included(controller)
    controller.extend ClassMethods
  end

  module ClassMethods
    def included(app)
      deferred.each { |(method, args, blk)| app.send method, *args, &blk }
    end

    def method_missing(meth, *args, &blk)
      defer meth, *args, &blk
      nil
    end

    def defer(what, *a, &blk)
      deferred << [what, a, blk]
    end

    def deferred
      @deferred ||= Array.new
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.7.4 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.7.3 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.7.2 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.7.1 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.7.0 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.9 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.8 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.7 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.6 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.5 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.4 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.3 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.2 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.1 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.6.0 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.5.17 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.5.16 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.5.15 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb
classiccms-0.5.14 vendor/bundle/gems/sinatra-support-1.2.2/lib/sinatra/support/appmodule.rb