Class: Sinatra::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/chiro/monkey_patch.rb

Instance Method Summary collapse

Instance Method Details

#old_route_evalObject

we monkey patch here because at this point we know the name of the route



4
# File 'lib/sinatra/chiro/monkey_patch.rb', line 4

alias_method :old_route_eval, :route_eval

#route_evalObject



5
6
7
8
9
10
# File 'lib/sinatra/chiro/monkey_patch.rb', line 5

def route_eval
  show_help if params.has_key? "help"
  validate_parameters if self.class.respond_to?(:validator)

  old_route_eval { yield }
end

#show_helpObject



23
24
25
26
27
28
29
30
# File 'lib/sinatra/chiro/monkey_patch.rb', line 23

def show_help
  if self.class.respond_to?(:validator)
    status 200
    erb_file = settings.erb_file
    views = settings.views_location
    throw :halt, "#{erb(erb_file, {:views => views}, :endpoint => self.class.documentation.document(env)) }"
  end
end

#validate_parametersObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/sinatra/chiro/monkey_patch.rb', line 12

def validate_parameters
  error = self.class.validator.validate(params, env)
  if error == "not found"
    status 404
    throw :halt, "Path not found"
  elsif error!= nil
    status 403
    throw :halt, "#{error}"
  end
end