Class: MetaWhere::Visitors::Visitor

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/meta_where/visitors/visitor.rb

Direct Known Subclasses

Attribute, Predicate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVisitor

Returns a new instance of Visitor.



11
12
13
# File 'lib/meta_where/visitors/visitor.rb', line 11

def initialize
  @tables = Hash.new {|hash, key| hash[key] = get_table(key)}
end

Instance Attribute Details

#join_dependencyObject

Returns the value of attribute join_dependency.



9
10
11
# File 'lib/meta_where/visitors/visitor.rb', line 9

def join_dependency
  @join_dependency
end

#tablesObject (readonly)

Returns the value of attribute tables.



8
9
10
# File 'lib/meta_where/visitors/visitor.rb', line 8

def tables
  @tables
end

Instance Method Details

#accept(object, parent = nil) ⇒ Object



33
34
35
# File 'lib/meta_where/visitors/visitor.rb', line 33

def accept(object, parent = nil)
  visit(object, parent)
end

#can_accept?(object) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/meta_where/visitors/visitor.rb', line 37

def can_accept?(object)
  respond_to? DISPATCH[object.class]
end

#get_table(parent_or_table_name = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/meta_where/visitors/visitor.rb', line 23

def get_table(parent_or_table_name = nil)
  if parent_or_table_name.is_a?(Symbol)
    Arel::Table.new(parent_or_table_name, :engine => @engine)
  elsif parent_or_table_name.respond_to?(:aliased_table_name)
    Arel::Table.new(parent_or_table_name.table_name, :as => parent_or_table_name.aliased_table_name, :engine => @engine)
  else
    @default_table
  end
end