Module: Sinatra::Scope

Defined in:
lib/sinatra/scope.rb

Instance Method Summary collapse

Instance Method Details

#scope(path, options = {}, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sinatra/scope.rb', line 20

def scope(path, options = {}, &block)
  case path
  when Class
    path = path.name
    path = path.demodulize unless options[:full_classname]
    path = path.underscore.dasherize
    path = path.pluralize unless options[:singular]
  else
    path = path.to_s
  end

  (@scopes ||= []) << path
  block.call
  @scopes.pop
end

#scopes(*paths, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/sinatra/scope.rb', line 36

def scopes(*paths, &block)
  @scopes ||= []
  paths.each do |path|
    @scopes << path.to_s
  end
  block.call
  paths.each do |path|
    @scopes.pop
  end
end