Class: Tzispa::RouteSet

Inherits:
Object
  • Object
show all
Defined in:
lib/tzispa/route_set.rb

Direct Known Subclasses

Engine::Rig::Router

Constant Summary collapse

CONTROLLERS_BASE =
'Tzispa::Controller'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, root = nil, ctl_module = nil) ⇒ RouteSet

Returns a new instance of RouteSet.



17
18
19
20
21
22
23
# File 'lib/tzispa/route_set.rb', line 17

def initialize(app, root = nil, ctl_module = nil)
  @router = HttpRouter.new
  @app = app
  @router.default Controller::HttpError.new(app, :error_404)
  @map_path = root unless root == '/'
  @ctl_module = ctl_module || CONTROLLERS_BASE
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



15
16
17
# File 'lib/tzispa/route_set.rb', line 15

def app
  @app
end

#map_pathObject (readonly)

Returns the value of attribute map_path.



15
16
17
# File 'lib/tzispa/route_set.rb', line 15

def map_path
  @map_path
end

#routerObject (readonly)

Returns the value of attribute router.



15
16
17
# File 'lib/tzispa/route_set.rb', line 15

def router
  @router
end

Instance Method Details

#add(route_id, path, controller, methods: nil, matching: nil) ⇒ Object



45
46
47
48
49
# File 'lib/tzispa/route_set.rb', line 45

def add(route_id, path, controller, methods: nil, matching: nil)
  add_route(route_id, path, to: build_controller(controller),
                            methods: methods,
                            matching: matching)
end

#call(env) ⇒ Object



41
42
43
# File 'lib/tzispa/route_set.rb', line 41

def call(env)
  @router.call env
end

#drawObject



51
52
53
# File 'lib/tzispa/route_set.rb', line 51

def draw
  yield if block_given?
end

#path(path_id, params = {}) ⇒ Object



37
38
39
# File 'lib/tzispa/route_set.rb', line 37

def path(path_id, params = {})
  "#{@map_path}#{@router.path path_id, params}"
end

#routes_definitionsObject



33
34
35
# File 'lib/tzispa/route_set.rb', line 33

def routes_definitions
  @routes_definitions ||= "config/routes/#{app.name}.rb"
end

#setupObject



25
26
27
28
29
30
31
# File 'lib/tzispa/route_set.rb', line 25

def setup
  draw do
    contents = File.read(routes_definitions)
    instance_eval(contents, File.basename(routes_definitions), 0)
  end
  self
end