Class: Rackr

Inherits:
Object
  • Object
show all
Includes:
Action
Defined in:
lib/rackr.rb,
lib/rackr/action.rb,
lib/rackr/router.rb,
lib/rackr/callback.rb,
lib/rackr/router/route.rb,
lib/rackr/router/errors.rb,
lib/rackr/router/build_request.rb

Defined Under Namespace

Modules: Action, Callback Classes: NotFound, Router

Instance Method Summary collapse

Methods included from Action

erb, #erb, #html, html, #html_response, html_response, included, json, #json, #json_response, json_response, #layout, layout, #redirect_response, redirect_response, #redirect_to, redirect_to, #response, response, #text, text, #text_response, text_response, view, view_response

Constructor Details

#initialize(config = {}, before: [], after: []) ⇒ Rackr

Returns a new instance of Rackr.



12
13
14
# File 'lib/rackr.rb', line 12

def initialize(config = {}, before: [], after: [])
  @router = Router.new(config, before: before, after: after)
end

Instance Method Details

#call(&block) ⇒ Object



16
17
18
19
20
# File 'lib/rackr.rb', line 16

def call(&block)
  instance_eval(&block)

  @router
end

#configObject



26
27
28
# File 'lib/rackr.rb', line 26

def config
  @router.config
end

#dbObject



30
31
32
# File 'lib/rackr.rb', line 30

def db
  @router.config[:db]
end

#error(endpoint = -> {}, &block) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/rackr.rb', line 54

def error(endpoint = -> {}, &block)
  if block_given?
    @router.add_error(block)
  else
    @router.add_error(endpoint)
  end
end

#not_found(endpoint = -> {}, &block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rackr.rb', line 46

def not_found(endpoint = -> {}, &block)
  if block_given?
    @router.add_not_found(block)
  else
    @router.add_not_found(endpoint)
  end
end

#r(name, before: [], after: [], as: nil, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rackr.rb', line 34

def r(name, before: [], after: [], as: nil, &block)
  @router.append_branch(
    name,
    branch_befores: before,
    branch_afters: after,
    as: as
  )
  instance_eval(&block)

  @router.clear_last_branch
end

#routesObject



22
23
24
# File 'lib/rackr.rb', line 22

def routes
  @router.routes
end