Module: Roy

Defined in:
lib/roy/base.rb,
lib/roy/halt.rb,
lib/roy/after.rb,
lib/roy/before.rb,
lib/roy/render.rb,
lib/roy/context.rb,
lib/roy/version.rb,
lib/roy/basic_auth.rb

Overview

This is the main module that applications should include.

Defined Under Namespace

Modules: After, BasicAuth, Before, ClassMethods, Halt, Render Classes: Context

Constant Summary collapse

Defaults =

Default options.

{allow: [:get], prefix: :'', use: [:halt]}
VERSION =

Roy version

[0, 5, 3]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extend the class with the ClassMethods module.



19
20
21
# File 'lib/roy/base.rb', line 19

def self.included(base)
  base.send(:extend, ClassMethods)
end

.versionObject

Return the version as a String.



6
7
8
# File 'lib/roy/version.rb', line 6

def self.version
  VERSION.join('.')
end

Instance Method Details

#call(env) ⇒ Object

A Rack-compliant #call method.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/roy/base.rb', line 29

def call(env)
  roy.prepare!(env)

  method = roy.env['REQUEST_METHOD'].downcase.to_sym
  roy.env['PATH_INFO'].sub!(/^([^\/])/, '/\1')

  method, was_head = :get, true if method == :head

  roy.response.status, body = catch(:halt) do
    roy.halt(405) unless roy.conf.allow.include?(method)
    prefixed_method = :"#{roy.conf.prefix}#{method}"
    [roy.response.status, send(prefixed_method, roy.env['PATH_INFO'])]
  end

  roy.response.write(body) unless was_head
  roy.response.finish
end

#royObject

Returns the application context or initialize it



24
25
26
# File 'lib/roy/base.rb', line 24

def roy
  @roy ||= Context.new(self)
end