Class: RRSE::Command::UpdateDB

Inherits:
Object
  • Object
show all
Defined in:
lib/rrse/update-db-command.rb

Overview

require “rdoc/ri/driver”

Defined Under Namespace

Classes: BitClustAdaptor, RIAdaptor

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ UpdateDB

Returns a new instance of UpdateDB.



12
13
14
15
16
# File 'lib/rrse/update-db-command.rb', line 12

def initialize(dir)
  @dir = dir
  @table = {}
  @index_table = {}
end

Class Method Details

.short_descriptionObject



8
9
10
# File 'lib/rrse/update-db-command.rb', line 8

def self.short_description
  "update database"
end

Instance Method Details

#merge_tables(table, index_table) ⇒ Object



46
47
48
49
# File 'lib/rrse/update-db-command.rb', line 46

def merge_tables(table, index_table)
  @table.merge!(table)
  @index_table.merge!(index_table)
end

#optionsObject



18
19
20
21
22
# File 'lib/rrse/update-db-command.rb', line 18

def options
  opts = OptionParser.new
  opts.banner = "Usage: rrse [global-options] update-db"
  opts
end

#read_bitclust_config(path) ⇒ Object



42
43
44
# File 'lib/rrse/update-db-command.rb', line 42

def read_bitclust_config(path)
  YAML.load_file(File.expand_path(path))
end

#run(argv) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rrse/update-db-command.rb', line 24

def run(argv)
  options.order!(argv)
  config = RRSE.load_config(@dir)
  config["sources"].each do |source|
    case source["type"]
    when "bitclust"
      merge_tables(*BitClustAdaptor.new(
        read_bitclust_config(source["config"]), source["version"], source["dbpath"]
      ).generate_tables)
    when "ri"
      raise "ri does not support"
    end
  end

  save_table(@table, @dir.join("table"))
  save_table(@index_table, @dir.join("index_table"))
end

#save_table(table, path) ⇒ Object



51
52
53
# File 'lib/rrse/update-db-command.rb', line 51

def save_table(table, path)
  File.open(path, "w"){|f| MessagePack.dump(table, f)}
end