Module: Sinatra::Sugar::ClassMethods
- Defined in:
- lib/sinatra/sugar.rb
Instance Attribute Summary collapse
-
#guessed_root ⇒ Object
writeonly
Sets the attribute guessed_root.
-
#root ⇒ Object
writeonly
Sets the attribute root.
Instance Method Summary collapse
-
#register(*extensions, &block) ⇒ Object
More advanced register: - If an exntesion is registered twice, the registered hook will only be called once.
-
#root_glob(*args, &block) ⇒ Object
Like root_path, but does return an array instead of a string.
-
#root_path(*args) ⇒ Object
Short hand so you can skip those ugly File.expand_path(File.join(File.dirname(__FILE__), …)) lines.
Instance Attribute Details
#guessed_root=(value) ⇒ Object (writeonly)
Sets the attribute guessed_root
28 29 30 |
# File 'lib/sinatra/sugar.rb', line 28 def guessed_root=(value) @guessed_root = value end |
#root=(value) ⇒ Object (writeonly)
Sets the attribute root
28 29 30 |
# File 'lib/sinatra/sugar.rb', line 28 def root=(value) @root = value end |
Instance Method Details
#register(*extensions, &block) ⇒ Object
More advanced register:
-
If an exntesion is registered twice, the registered hook will only be called once.
32 33 34 35 |
# 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) ⇒ Object
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
52 53 54 |
# File 'lib/sinatra/sugar.rb', line 52 def root_glob(*args, &block) Dir.glob(root_path(*args)).each(&block) end |
#root_path(*args) ⇒ Object
Short hand so you can skip those ugly File.expand_path(File.join(File.dirname(__FILE__), …)) lines.
39 40 41 42 43 |
# File 'lib/sinatra/sugar.rb', line 39 def root_path(*args) relative = File.join(*args) return relative if relative. == relative root. / relative end |