Module: Sinatra::Resources
- Defined in:
- lib/sinatra/resources.rb
Instance Method Summary collapse
- #make_path(path) ⇒ Object
-
#member(&block) ⇒ Object
Shortcut for “resource ‘:id’”.
-
#resource(path, &block) ⇒ Object
Define a new resource block.
Instance Method Details
#make_path(path) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/sinatra/resources.rb', line 25 def make_path(path) return path if path.is_a?(Regexp) || @path_parts.nil? || @path_parts.empty? path = path.to_s if path.is_a?(Symbol) route = @path_parts.join('/') route += '/' + path if path '/' + route.squeeze('/') end |
#member(&block) ⇒ Object
Shortcut for “resource ‘:id’”.
20 21 22 23 |
# File 'lib/sinatra/resources.rb', line 20 def member(&block) raise "Nested member do..end must be within resource do..end" if @path_parts.nil? || @path_parts.empty? resource(':id', &block) end |
#resource(path, &block) ⇒ Object
Define a new resource block. Resources can be nested of arbitrary depth.
12 13 14 15 16 17 |
# File 'lib/sinatra/resources.rb', line 12 def resource(path, &block) raise "Resource path cannot be nil" if path.nil? (@path_parts ||= []) << path block.call @path_parts.pop end |