Class: DbDumper::QueryBuilder::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/db_dumper/query_builder/query.rb

Overview

Wrapper under ActiveRecord::Relation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_table, exist_ar = nil) ⇒ Query

Returns a new instance of Query.



10
11
12
13
# File 'lib/db_dumper/query_builder/query.rb', line 10

def initialize(raw_table, exist_ar = nil)
  @table  = Table.from(raw_table)
  @ar     = exist_ar || table.ar.all
end

Instance Attribute Details

#arObject (readonly)

Returns the value of attribute ar.



8
9
10
# File 'lib/db_dumper/query_builder/query.rb', line 8

def ar
  @ar
end

#tableObject (readonly)

Returns the value of attribute table.



8
9
10
# File 'lib/db_dumper/query_builder/query.rb', line 8

def table
  @table
end

Instance Method Details

#joins(*args) ⇒ Object



19
20
21
22
# File 'lib/db_dumper/query_builder/query.rb', line 19

def joins(*args)
  raise 'Only simple string for joins supported' unless args.size == 1 && args[0].is_a?(String)
  self.class.new(table, ar.joins(*args))
end

#select(*args) ⇒ Object



24
25
26
# File 'lib/db_dumper/query_builder/query.rb', line 24

def select(*args)
  self.class.new(table, ar.select(*args))
end

#table_nameObject



28
29
30
# File 'lib/db_dumper/query_builder/query.rb', line 28

def table_name
  table.table_name
end

#to_sqlObject



32
33
34
# File 'lib/db_dumper/query_builder/query.rb', line 32

def to_sql
  @ar.to_sql
end

#where(*args) ⇒ Object



15
16
17
# File 'lib/db_dumper/query_builder/query.rb', line 15

def where(*args)
  self.class.new(table, ar.where(*args))
end