Class: Radical::Routes

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

Direct Known Subclasses

Routes

Class Method Summary collapse

Class Method Details

.parentsObject



16
17
18
# File 'lib/radical/routes.rb', line 16

def parents
  @parents ||= []
end

.resource(*names) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/radical/routes.rb', line 28

def resource(*names)
  classes = names.map { |c| Object.const_get(c) }

  classes.each do |klass|
    router.add_resource(klass)
  end
end

.resources(*names, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/radical/routes.rb', line 37

def resources(*names, &block)
  classes = names.map { |c| Object.const_get(c) }

  classes.each do |klass|
    if parents.any?
      router.add_resources(klass, parents: @parents)

      # only one level of nesting
      @parents = []
    else
      router.add_resources(klass)
    end
  end

  return unless block

  @parents = classes

  block.call
end

.root(name) ⇒ Object



21
22
23
24
25
# File 'lib/radical/routes.rb', line 21

def root(name)
  klass = Object.const_get(name)

  router.add_root(klass)
end

.routerObject



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

def router
  @router ||= Router.new
end