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

Constant Summary collapse

HTTP_METHODS =
%w[GET POST DELETE PUT TRACE OPTIONS PATCH]

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.



14
15
16
# File 'lib/rackr.rb', line 14

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

Instance Method Details

#call(&block) ⇒ Object



18
19
20
21
22
# File 'lib/rackr.rb', line 18

def call(&block)
  instance_eval(&block)

  @router
end

#configObject



28
29
30
# File 'lib/rackr.rb', line 28

def config
  @router.config
end

#dbObject



32
33
34
# File 'lib/rackr.rb', line 32

def db
  @router.config[:db]
end

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



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

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

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



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

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: [], &block) ⇒ Object



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

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

  @router.clear_last_branch
end

#routesObject



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

def routes
  @router.routes
end