Class: MetaWhere::Visitors::Visitor
- Inherits:
-
Object
- Object
- MetaWhere::Visitors::Visitor
- Includes:
- Utility
- Defined in:
- lib/meta_where/visitors/visitor.rb
Instance Attribute Summary collapse
-
#join_dependency ⇒ Object
readonly
Returns the value of attribute join_dependency.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #accept(object, parent = nil) ⇒ Object
- #can_accept?(object) ⇒ Boolean
- #get_table(parent_or_table_name = nil) ⇒ Object
-
#initialize(join_dependency) ⇒ Visitor
constructor
A new instance of Visitor.
Constructor Details
#initialize(join_dependency) ⇒ Visitor
Returns a new instance of Visitor.
10 11 12 13 14 15 16 |
# File 'lib/meta_where/visitors/visitor.rb', line 10 def initialize(join_dependency) @join_dependency = join_dependency jb = join_dependency.join_base @engine = jb.arel_engine @default_table = Arel::Table.new(jb.table_name, :as => jb.aliased_table_name, :engine => @engine) @tables = Hash.new {|hash, key| hash[key] = get_table(key)} end |
Instance Attribute Details
#join_dependency ⇒ Object (readonly)
Returns the value of attribute join_dependency.
8 9 10 |
# File 'lib/meta_where/visitors/visitor.rb', line 8 def join_dependency @join_dependency end |
#tables ⇒ Object (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
28 29 30 |
# File 'lib/meta_where/visitors/visitor.rb', line 28 def accept(object, parent = nil) visit(object, parent) end |
#can_accept?(object) ⇒ Boolean
32 33 34 |
# File 'lib/meta_where/visitors/visitor.rb', line 32 def can_accept?(object) respond_to? DISPATCH[object.class] end |
#get_table(parent_or_table_name = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/meta_where/visitors/visitor.rb', line 18 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 |