Class: LogStash::Filters::Jdbc::DbObject

Inherits:
Validatable show all
Defined in:
lib/logstash/filters/jdbc/db_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Validatable

find_validation_errors, #formatted_errors, #initialize, #valid?

Constructor Details

This class inherits a constructor from LogStash::Filters::Jdbc::Validatable

Instance Attribute Details

#columnsObject (readonly)



10
11
12
# File 'lib/logstash/filters/jdbc/db_object.rb', line 10

def columns
  @columns
end

#index_columnsObject (readonly)



10
11
12
# File 'lib/logstash/filters/jdbc/db_object.rb', line 10

def index_columns
  @index_columns
end

#nameObject (readonly)



10
11
12
# File 'lib/logstash/filters/jdbc/db_object.rb', line 10

def name
  @name
end

#preserve_existingObject (readonly)



10
11
12
# File 'lib/logstash/filters/jdbc/db_object.rb', line 10

def preserve_existing
  @preserve_existing
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
# File 'lib/logstash/filters/jdbc/db_object.rb', line 28

def <=>(other)
  @name <=> other.name
end

#build(db) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/logstash/filters/jdbc/db_object.rb', line 12

def build(db)
  return unless valid?
  if db.nil?
    raise "DbObject given a database instance that is nil"
  end
  schema_gen = db.create_table_generator()
  @columns.each {|col| schema_gen.column(col.name, col.datatype)}
  schema_gen.index(@index_columns) unless @index_columns.empty?
  options = {:generator => schema_gen}
  if @preserve_existing
    db.create_table?(@name, options)
  else
    db.create_table(@name, options)
  end
end

#inspectObject



36
37
38
# File 'lib/logstash/filters/jdbc/db_object.rb', line 36

def inspect
  "<LogStash::Filters::Jdbc::DbObject name: #{@name}, columns: #{@columns.inspect}>"
end

#to_sObject



32
33
34
# File 'lib/logstash/filters/jdbc/db_object.rb', line 32

def to_s
  inspect
end