module Sinatra::Sugar::ClassMethods

Attributes

guessed_root[W]
root[W]

Public Instance Methods

register(*extensions, &block) click to toggle source

More advanced register:

  • If an exntesion is registered twice, the registered hook will only be called once.

# File lib/sinatra/sugar.rb, line 32
def register(*extensions, &block)
  extensions.reject! { |e| self.extensions.include? e }
  super(*extensions, &block)
end
root_glob(*args, &block) click to toggle source

Like #root_path, but does return an array instead of a string. Optionally takes a block that will be called for each entry once.

Example:

class Foo < BigBand
  root_glob("app", "{models,views,controllers}", "*.rb") { |file| load file }
end
# File lib/sinatra/sugar.rb, line 52
def root_glob(*args, &block)
  Dir.glob(root_path(*args)).each(&block)
end
root_path(*args) click to toggle source

Short hand so you can skip those ugly File.expand_path(File.join(File.dirname(__FILE__), ...)) lines.

# File lib/sinatra/sugar.rb, line 39
def root_path(*args)
  relative = File.join(*args)
  return relative if relative.expand_path == relative
  root.expand_path / relative
end