Module: Pendragon

Defined in:
lib/pendragon.rb,
lib/pendragon/errors.rb,
lib/pendragon/linear.rb,
lib/pendragon/router.rb,
lib/pendragon/realism.rb,
lib/pendragon/version.rb,
lib/pendragon/constants.rb

Defined Under Namespace

Modules: Errors Classes: Linear, Realism, Router

Constant Summary collapse

DEFAULT_TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Type to use if no type is given.

:realism
VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Class, #new

Returns router by given name.

Examples:

Pendragon[:realism] #=> Pendragon::Realism

Parameters:

  • name (Symbol)

    a router type identifier

Returns:

  • (Class, #new)

Raises:

  • (ArgumentError)

    if the name is not supported



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pendragon.rb', line 40

def self.[](name)
  @types.fetch(normalized = normalize_type(name)) do
    @mutex.synchronize do
      error = try_require "pendragon/#{normalized}"
      @types.fetch(normalized) do
        fail ArgumentError,
          "unsupported type %p #{ " (#{error.message})" if error }" % name
      end
    end
  end
end

.new(type: DEFAULT_TYPE) { ... } ⇒ Object

Creates a new router.

Examples:

creating new routes.

require 'pendragon'

 Pendragon.new do
   get('/') { [200, {}, ['hello world']] }
   namespace :users do
     get('/',    to: ->(env) { [200, {}, ['User page index']] })
     get('/:id', to: UserApplication.new)
   end
 end

Yields:

  • block for definig routes, it will be evaluated in instance context.

Yield Returns:



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

def self.new(type: DEFAULT_TYPE, &block)
  type ||= DEFAULT_TYPE
  self[type].new(&block)
end