Class: Clerq::Services::QueryNode

Inherits:
Service
  • Object
show all
Defined in:
lib/clerq/services/query_node.rb

Overview

Provides repository nodes assembly Usage

QueryAssembly.(asse:, query:)
QueryAssembly.(query_string)

Rules for root node:

when query not passed, it return the whole hierarchy
when nodes not found, it returns empty root node with meta[:query]
when query returns one single node, it returns this node
when query returns mare than one nodes, then
  * it creates empty root node with meta[:query]
  * and places found nodes to the root

Returns:

  • (Node)

    assembly of repository nodes

Instance Method Summary collapse

Methods inherited from Service

call

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/clerq/services/query_node.rb', line 25

def call
  proc = prepare_query unless @query.empty?

  arry = @assembly.select{|node| proc.call(node) }
  return arry.first.orphan! if arry.size == 1

  node = Node.new(title: Clerq.title, meta: {query: @query})
  arry.each{|n| node << n.orphan!}
  node
end