Class: AhoyCaptain::VisitQuery

Inherits:
ApplicationQuery show all
Defined in:
app/queries/ahoy_captain/visit_query.rb

Instance Attribute Summary

Attributes inherited from ApplicationQuery

#params

Instance Method Summary collapse

Methods inherited from ApplicationQuery

call, inherited, #initialize, #inspect

Constructor Details

This class inherits a constructor from AhoyCaptain::ApplicationQuery

Instance Method Details

#buildObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/queries/ahoy_captain/visit_query.rb', line 4

def build
  shared_context = Ransack::Context.for(AhoyCaptain.visit)

  search_parents = AhoyCaptain.visit.ransack(
    ransack_params_for(:visit).reject { |k,v| k.start_with?("events_") }, context: shared_context
  )
  search_children = AhoyCaptain.event.ransack(
    ransack_params_for(:event).reject { |k,v| k.start_with?("visit_") || k == :c }.transform_keys { |key| "events_#{key}" }, context: shared_context
  )

  shared_conditions = [search_parents, search_children].map { |search|
    Ransack::Visitor.new.accept(search.base)
  }

  AhoyCaptain.visit.joins(shared_context.join_sources)
        .where(shared_conditions.reduce(&:and))

end

#is_a?(other) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'app/queries/ahoy_captain/visit_query.rb', line 23

def is_a?(other)
  if other == ActiveRecord::Relation
    return true
  end

  super(other)
end