Class: Mayu::Routing::Routes::Route

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayu/routing/routes.rb

Direct Known Subclasses

Named, Param

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoute

Returns a new instance of Route.



18
19
20
21
22
23
24
# File 'lib/mayu/routing/routes.rb', line 18

def initialize
  @page = nil
  @layout = nil
  @not_found = nil
  @named = T.let({}, T::Hash[String, Named])
  @params = T.let([], T::Array[Param])
end

Instance Attribute Details

#layoutObject

Returns the value of attribute layout.



13
14
15
# File 'lib/mayu/routing/routes.rb', line 13

def layout
  @layout
end

#not_foundObject

Returns the value of attribute not_found.



15
16
17
# File 'lib/mayu/routing/routes.rb', line 15

def not_found
  @not_found
end

#pageObject

Returns the value of attribute page.



11
12
13
# File 'lib/mayu/routing/routes.rb', line 11

def page
  @page
end

Instance Method Details

#add_route(route) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/mayu/routing/routes.rb', line 27

def add_route(route)
  case route
  when Named
    @named[route.name] = route
  when Param
    @params.push(route)
  else
    raise TypeError, "Unknown route type: #{route.class}"
  end
end

#match(part) ⇒ Object



39
40
41
# File 'lib/mayu/routing/routes.rb', line 39

def match(part)
  @named.fetch(part) { @params.find { _1.match?(part) } }
end

#match?(part) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mayu/routing/routes.rb', line 44

def match?(part)
  true
end