Module: Sinatra::Namespace::NestedMethods

Defined in:
lib/sinatra/namespace.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



116
117
118
119
120
121
# File 'lib/sinatra/namespace.rb', line 116

def method_missing(name, *args, &block)
  Monkey.invisible { super }
rescue NameError => error # allowes adding method_missing in mixins
  raise error unless base.respond_to? name and forward? name
  base.send(name, *args, &block)
end

Instance Method Details

#after(&block) ⇒ Object



63
64
65
# File 'lib/sinatra/namespace.rb', line 63

def after(&block)
  after_filters << block
end

#after_filtersObject



55
56
57
# File 'lib/sinatra/namespace.rb', line 55

def after_filters
  @after_filters ||= []
end

#base(value = nil) ⇒ Object



19
20
21
22
# File 'lib/sinatra/namespace.rb', line 19

def base(value = nil)
  @base = value if value
  @base
end

#before(&block) ⇒ Object



59
60
61
# File 'lib/sinatra/namespace.rb', line 59

def before(&block)
  before_filters << block
end

#before_filtersObject



51
52
53
# File 'lib/sinatra/namespace.rb', line 51

def before_filters
  @before_filters ||= []
end

#delete(name = nil, options = {}, &block) ⇒ Object



32
# File 'lib/sinatra/namespace.rb', line 32

def delete(name = nil, options = {}, &block); prefixed(:delete, name, options, &block); end

#error(codes = Exception, &block) ⇒ Object



35
36
37
# File 'lib/sinatra/namespace.rb', line 35

def error(codes=Exception, &block)
  [*codes].each { |c| errors[c] = block }
end

#errorsObject



10
11
12
# File 'lib/sinatra/namespace.rb', line 10

def errors
  @errors ||= {}
end

#get(name = nil, options = {}, &block) ⇒ Object



29
# File 'lib/sinatra/namespace.rb', line 29

def get(name = nil, options = {}, &block);    prefixed(:get,    name, options, &block); end

#head(name = nil, options = {}, &block) ⇒ Object



33
# File 'lib/sinatra/namespace.rb', line 33

def head(name = nil, options = {}, &block);   prefixed(:head,   name, options, &block); end

#helpers(*modules, &block) ⇒ Object



24
25
26
27
# File 'lib/sinatra/namespace.rb', line 24

def helpers(*modules, &block)
  modules.each { |m| include m }
  class_eval(&block) if block
end

#methods(*args) ⇒ Object



47
48
49
# File 'lib/sinatra/namespace.rb', line 47

def methods(*args)
  (super + base.methods(*args).select { |m| forward? m }).uniq
end

#not_found(&block) ⇒ Object



39
40
41
# File 'lib/sinatra/namespace.rb', line 39

def not_found(&block)
  error(404, &block)
end

#post(name = nil, options = {}, &block) ⇒ Object



31
# File 'lib/sinatra/namespace.rb', line 31

def post(name = nil, options = {}, &block);   prefixed(:post,   name, options, &block); end

#prefix(value = nil) ⇒ Object



14
15
16
17
# File 'lib/sinatra/namespace.rb', line 14

def prefix(value = nil)
  @prefix = value if value
  @prefix
end

#put(name = nil, options = {}, &block) ⇒ Object



30
# File 'lib/sinatra/namespace.rb', line 30

def put(name = nil, options = {}, &block);    prefixed(:put,    name, options, &block); end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sinatra/namespace.rb', line 43

def respond_to?(name)
  super or (base.respond_to? name and forward? name)
end