Module: Graphiti::ActiveGraph::Query

Defined in:
lib/graphiti/active_graph/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deep_sortObject (readonly)

Returns the value of attribute deep_sort.



3
4
5
# File 'lib/graphiti/active_graph/query.rb', line 3

def deep_sort
  @deep_sort
end

Instance Method Details

#filtersObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/graphiti/active_graph/query.rb', line 5

def filters
  @filters ||= begin
    {}.tap do |hash|
      (@params[:filter] || {}).each_pair do |name, value|
        name = name.to_sym

        if legacy_nested?(name)
          value.keys.each do |key|
            filter_name = key.to_sym
            filter_value = value[key]

            if @resource.get_attr!(filter_name, :filterable, request: true)
              hash[filter_name] = filter_value
            end
          end
        elsif nested?(name)
          name = name.to_s.split(".").last.to_sym
          validate!(name, :filterable)
          hash[name] = value
        else
          hash[name] = value
        end
      end
    end
  end
end

#parse_sort_criteria_hash(hash) ⇒ Object



39
40
41
# File 'lib/graphiti/active_graph/query.rb', line 39

def parse_sort_criteria_hash(hash)
  hash.map { |key, value| [key.to_s.split('.').map(&:to_sym), value] }.to_h
end

#sortsObject



32
33
34
35
36
37
# File 'lib/graphiti/active_graph/query.rb', line 32

def sorts
  return super unless (sort = params[:sort]) && sort.include?('.')

  @deep_sort = sort_criteria(sort)
  []
end