Class: Jsonatra::Base

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/jsonatra.rb,
lib/jsonatra/break_rest.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(*args, &block) ⇒ Object



11
12
13
14
# File 'lib/jsonatra/break_rest.rb', line 11

def get(*args, &block)
  sinatra_get *args, &block
  post *args, &block
end

.sinatra_getObject

because some parameters can be too large for normal GET query strings, all GET routes also accept a POST with body data, with the same parameter names and behavior



10
# File 'lib/jsonatra/break_rest.rb', line 10

alias_method :sinatra_get, :get

Instance Method Details

#call!(env) ⇒ Object

copied here so we can override Response.new with Jsonatra::Response.new

github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb#L880



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jsonatra.rb', line 25

def call!(env) # :nodoc:
  @env      = env
  @request  = ::Sinatra::Request.new(env)
  @response = ::Jsonatra::Response.new
  @params   = indifferent_params(@request.params)
  template_cache.clear if settings.reload_templates
  force_encoding(@params)

  @response['Content-Type'] = nil
  invoke { dispatch! }
  invoke { error_block!(response.status) } unless @env['sinatra.error']

  unless @response['Content-Type']
    if Array === body and body[0].respond_to? :content_type
      content_type body[0].content_type
    else
      content_type :html
    end
  end

  @response.finish
end