Class: Groonga::DatabaseDumper

Inherits:
Object
  • Object
show all
Defined in:
lib/groonga/dumper.rb

Overview

データベースの内容をgrn式形式の文字列として出力するクラス。

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DatabaseDumper

Returns a new instance of DatabaseDumper.



45
46
47
# File 'lib/groonga/dumper.rb', line 45

def initialize(options={})
  @options = options
end

Class Method Details

.dump(options = {}) ⇒ Object

Dump database

TODO: document options paramter



39
40
41
42
# File 'lib/groonga/dumper.rb', line 39

def dump(options={})
  dumper = new(options)
  dumper.dump
end

Instance Method Details

#dumpObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/groonga/dumper.rb', line 49

def dump
  options = @options.dup
  have_output = !@options[:output].nil?
  options[:output] ||= Dumper.default_output
  options[:error_output] ||= Dumper.default_output
  if options[:database].nil?
    options[:context] ||= Groonga::Context.default
    options[:database] = options[:context].database
  end
  options[:dump_schema] = true if options[:dump_schema].nil?
  options[:dump_indexes] = true if options[:dump_indexes].nil?
  options[:dump_tables] = true if options[:dump_tables].nil?

  if options[:dump_schema] or options[:dump_indexes]
    schema_dumper = SchemaDumper.new(options.merge(:syntax => :command))
  end

  if options[:dump_schema]
    dump_plugins(options)
    schema_dumper.dump_tables
    if schema_dumper.have_reference_columns?
      options[:output].write("\n")
      schema_dumper.dump_reference_columns
    end
  end
  dump_tables(options) if options[:dump_tables]
  if options[:dump_indexes] and schema_dumper.have_index_columns?
    options[:output].write("\n")
    schema_dumper.dump_index_columns
  end

  if have_output
    nil
  else
    options[:output].string
  end
end