Module: Sinatra::Contrib::Loader

Included in:
Sinatra::Contrib, Common, Custom
Defined in:
lib/sinatra/contrib/setup.rb

Instance Method Summary collapse

Instance Method Details

#autoload(name, path = nil, method = nil) ⇒ Object



20
21
22
23
24
# File 'lib/sinatra/contrib/setup.rb', line 20

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

#extensionsObject



8
9
10
# File 'lib/sinatra/contrib/setup.rb', line 8

def extensions
  @extensions ||= {:helpers => [], :register => []}
end

#helpers(name, path = nil) ⇒ Object



16
17
18
# File 'lib/sinatra/contrib/setup.rb', line 16

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

#register(name, path = nil) ⇒ Object



12
13
14
# File 'lib/sinatra/contrib/setup.rb', line 12

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

#registered(base) ⇒ Object



26
27
28
29
30
31
# File 'lib/sinatra/contrib/setup.rb', line 26

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