Sha256: 6405db96e6f55b4fc69d14627e48af8bf64703973b6ed551d4e78c637c7a50ee

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

require 'sinatra/base'
require 'sinatra/contrib/version'
require 'backports'

module Sinatra
  module Contrib
    module Loader
      def extensions
        @extensions ||= {:helpers => [], :register => []}
      end

      def register(name, path = nil)
        autoload name, path, :register
      end

      def helpers(name, path = nil)
        autoload name, path, :helpers
      end

      def autoload(name, path = nil, method = nil)
        path ||= "sinatra/#{name.to_s.underscore}"
        extensions[method] << name if method
        Sinatra.autoload(name, path)
      end

      def registered(base)
        @extensions.each do |meth, list|
          list = list.map { |name| Sinatra.const_get name }
          base.send(meth, *list) unless base == ::Sinatra::Application
        end
      end
    end

    module Common
      extend Loader
    end

    module Custom
      extend Loader
    end

    module All
      def self.registered(base)
        base.register Common, Custom
      end
    end

    extend Loader
    def self.registered(base)
      base.register Common, Custom
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
sinatra-contrib-1.3.2 lib/sinatra/contrib/setup.rb
sinatra-contrib-1.3.1 lib/sinatra/contrib/setup.rb
sinatra-contrib-1.3.0 lib/sinatra/contrib/setup.rb
pirj-sinatra-contrib-1.3.0 lib/sinatra/contrib/setup.rb