Class: Releaf::Content::BuildRouteObjects

Inherits:
Object
  • Object
show all
Includes:
InstanceCache, Service
Defined in:
app/services/releaf/content/build_route_objects.rb

Instance Method Summary collapse

Instance Method Details

#build_path(node) ⇒ Object



44
45
46
47
48
49
# File 'app/services/releaf/content/build_route_objects.rb', line 44

def build_path(node)
  path = "/"
  path += node.self_and_ancestors_array.map(&:slug).join("/")
  path += node.trailing_slash_for_path? ? "/" : ""
  path
end

#build_route_object(node) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/services/releaf/content/build_route_objects.rb', line 25

def build_route_object(node)
  node.preloaded_self_and_ancestors = self_and_ancestors(node)

  if node.available?
    route = Releaf::Content::Route.new
    route.node_class = node.class
    route.node_id = node.id.to_s
    route.path = build_path(node)
    route.locale = node.self_and_ancestors_array.first.locale
    route.default_controller = default_controller
    route.site = Releaf::Content.routing[node.class.name][:site]
    route
  end
end

#callObject



13
14
15
# File 'app/services/releaf/content/build_route_objects.rb', line 13

def call
  content_nodes.map { |node| build_route_object(node) }.compact
end

#content_nodesObject



17
18
19
# File 'app/services/releaf/content/build_route_objects.rb', line 17

def content_nodes
  nodes.select { |item| item.content_type == node_content_class.name }
end

#nodesObject



21
22
23
# File 'app/services/releaf/content/build_route_objects.rb', line 21

def nodes
  node_class.all
end

#self_and_ancestors(node) ⇒ Object



40
41
42
# File 'app/services/releaf/content/build_route_objects.rb', line 40

def self_and_ancestors(node)
  nodes.select { |item| item.lft <= node.lft && item.rgt >= node.rgt }.sort_by(&:depth)
end