Class: Tzispa::RouteSet
- Inherits:
-
Object
- Object
- Tzispa::RouteSet
- Defined in:
- lib/tzispa/route_set.rb
Direct Known Subclasses
Constant Summary collapse
- CONTROLLERS_BASE =
'Tzispa::Controller'
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#map_path ⇒ Object
readonly
Returns the value of attribute map_path.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Instance Method Summary collapse
- #add(route_id, path, controller, methods: nil, matching: nil) ⇒ Object
- #call(env) ⇒ Object
- #draw ⇒ Object
-
#initialize(app, root = nil, ctl_module = nil) ⇒ RouteSet
constructor
A new instance of RouteSet.
- #path(path_id, params = {}) ⇒ Object
- #routes_definitions ⇒ Object
- #setup ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
15 16 17 |
# File 'lib/tzispa/route_set.rb', line 15 def app @app end |
#map_path ⇒ Object (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 |
#router ⇒ Object (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 |
#draw ⇒ Object
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_definitions ⇒ Object
33 34 35 |
# File 'lib/tzispa/route_set.rb', line 33 def routes_definitions @routes_definitions ||= "config/routes/#{app.name}.rb" end |
#setup ⇒ Object
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 |