Class: ActiveRecord::HierarchicalQuery::Adapters::Abstract Private

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/hierarchical_query/adapters/abstract.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

PostgreSQL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Abstract

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Abstract.



24
25
26
27
# File 'lib/active_record/hierarchical_query/adapters/abstract.rb', line 24

def initialize(query)
  @query = query
  @table = klass.arel_table
end

Instance Attribute Details

#queryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/active_record/hierarchical_query/adapters/abstract.rb', line 10

def query
  @query
end

#tableObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/active_record/hierarchical_query/adapters/abstract.rb', line 10

def table
  @table
end

Class Method Details

.visitors(*visitors_classes) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
# File 'lib/active_record/hierarchical_query/adapters/abstract.rb', line 16

def visitors(*visitors_classes)
  define_method :visitors do
    @visitors ||= visitors_classes.map { |klass| klass.new(@query) }
  end
end

Instance Method Details

#visit(kind, object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Examples:

visit(:recursive_term, recursive_term.arel)


31
32
33
34
35
36
37
# File 'lib/active_record/hierarchical_query/adapters/abstract.rb', line 31

def visit(kind, object)
  method_name = "visit_#{kind}"

  visitors.reduce(object) do |*, visitor|
    visitor.send(method_name, object) if visitor.respond_to?(method_name)
  end
end