Module: Droonga::DatabaseScanner
- Defined in:
- lib/droonga/database_scanner.rb
Instance Method Summary collapse
- #each_index_columns(&block) ⇒ Object
- #each_table(&block) ⇒ Object
- #index_column?(column) ⇒ Boolean
- #index_only_table?(table) ⇒ Boolean
- #n_columns ⇒ Object
- #n_records ⇒ Object
- #n_tables ⇒ Object
- #reference_table?(table) ⇒ Boolean
- #table?(object) ⇒ Boolean
- #total_n_objects ⇒ Object
Instance Method Details
#each_index_columns(&block) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/droonga/database_scanner.rb', line 98 def each_index_columns(&block) each_table do |table| table.columns.each do |column| yield(column) if index_column?(column) end end end |
#each_table(&block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/droonga/database_scanner.rb', line 60 def each_table(&block) = { :ignore_missing_object => true, :order_by => :key, } reference_tables = [] @context.database.each() do |object| next unless table?(object) if reference_table?(object) reference_tables << object next end yield(object) end reference_tables.each do |reference_table| yield(object) end end |
#index_column?(column) ⇒ Boolean
94 95 96 |
# File 'lib/droonga/database_scanner.rb', line 94 def index_column?(column) column.is_a?(::Groonga::IndexColumn) end |
#index_only_table?(table) ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/droonga/database_scanner.rb', line 87 def index_only_table?(table) return false if table.columns.empty? table.columns.all? do |column| index_column?(column) end end |
#n_columns ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/droonga/database_scanner.rb', line 28 def n_columns n_columns = 0 each_table do |table| n_columns += table.columns.size end n_columns end |
#n_records ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/droonga/database_scanner.rb', line 36 def n_records n_records = 0 each_table do |table| unless index_only_table?(table) n_records += table.size end end n_records end |
#n_tables ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/droonga/database_scanner.rb', line 20 def n_tables n_tables = 0 each_table do |table| n_tables += 1 end n_tables end |
#reference_table?(table) ⇒ Boolean
83 84 85 |
# File 'lib/droonga/database_scanner.rb', line 83 def reference_table?(table) table.support_key? and table?(table.domain) end |
#table?(object) ⇒ Boolean
79 80 81 |
# File 'lib/droonga/database_scanner.rb', line 79 def table?(object) object.is_a?(::Groonga::Table) end |
#total_n_objects ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/droonga/database_scanner.rb', line 46 def total_n_objects n_tables = 0 n_columns = 0 n_records = 0 each_table do |table| n_tables += 1 n_columns += table.columns.size unless index_only_table?(table) n_records += table.size end end n_tables + n_columns + n_records end |