Module: Arql::Extension

Extended by:
ActiveSupport::Concern
Defined in:
lib/arql/definition.rb

Instance Method Summary collapse

Instance Method Details

#dump(filename, batch_size = 500) ⇒ Object



54
55
56
# File 'lib/arql/definition.rb', line 54

def dump(filename, batch_size=500)
  [self].dump(filename, batch_size)
end

#t(**options) ⇒ Object



8
9
10
11
12
# File 'lib/arql/definition.rb', line 8

def t(**options)
  puts Terminal::Table.new { |t|
    v(**options).each { |row| t << (row || :separator) }
  }
end

#to_insert_sqlObject



38
39
40
# File 'lib/arql/definition.rb', line 38

def to_insert_sql
  self.class.to_insert_sql([self])
end

#to_upsert_sqlObject



42
43
44
# File 'lib/arql/definition.rb', line 42

def to_upsert_sql
  self.class.to_upsert_sql([self])
end

#v(**options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/arql/definition.rb', line 23

def v(**options)
  t = []
  t << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
  t << nil
  compact_mode = options[:compact] || false
  self.class.connection.columns(self.class.table_name).each do |column|
    value = read_attribute(column.name)
    if compact_mode && value.blank?
      next
    end
    t << [column.name, value, column.sql_type, column.comment || '']
  end
  t
end

#vdObject



14
15
16
17
18
19
20
21
# File 'lib/arql/definition.rb', line 14

def vd
  VD.new do |vd|
    vd << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
    self.class.connection.columns(self.class.table_name).each do |column|
      vd << [column.name, read_attribute(column.name), column.sql_type, column.comment || '']
    end
  end
end

#write_csv(filename, *fields, **options) ⇒ Object



46
47
48
# File 'lib/arql/definition.rb', line 46

def write_csv(filename, *fields, **options)
  [self].write_csv(filename, *fields, **options)
end

#write_excel(filename, *fields, **options) ⇒ Object



50
51
52
# File 'lib/arql/definition.rb', line 50

def write_excel(filename, *fields, **options)
  [self].write_excel(filename, *fields, **options)
end