Class: Relaton::Cli::SubcommandDb

Inherits:
Thor
  • Object
show all
Includes:
Relaton::Cli
Defined in:
lib/relaton/cli/subcommand_db.rb

Constant Summary

Constants included from Relaton::Cli

VERSION

Instance Method Summary collapse

Methods included from Relaton::Cli

parse_xml, processor, relaton, start

Instance Method Details

#clearObject



29
30
31
32
# File 'lib/relaton/cli/subcommand_db.rb', line 29

def clear
  Relaton.db.clear
  warn "Cache DB is cleared"
end

#create(dir = nil) ⇒ Object



10
11
12
13
14
# File 'lib/relaton/cli/subcommand_db.rb', line 10

def create(dir = nil)
  db = Relaton.db (dir && File.expand_path(dir))
  path = db.instance_variable_get(:@db).dir
  warn "Cache DB is in \"#{path}\""
end

#doctype(ref) ⇒ Object



68
69
70
71
# File 'lib/relaton/cli/subcommand_db.rb', line 68

def doctype(ref)
  io = IO.new($stdout.fcntl(::Fcntl::F_DUPFD), mode: "w:UTF-8")
  io.puts Relaton.db.docid_type(ref)
end

#fetch(code) ⇒ Object



43
44
45
46
47
# File 'lib/relaton/cli/subcommand_db.rb', line 43

def fetch(code)
  io = IO.new($stdout.fcntl(::Fcntl::F_DUPFD), mode: "w:UTF-8")
  opts = options.merge(fetch_db: true)
  io.puts(fetch_document(code, opts) || supported_type_message)
end

#fetch_all(text = nil) ⇒ Object

rubocop:disable Metrics/AbcSize



56
57
58
59
60
61
62
63
64
# File 'lib/relaton/cli/subcommand_db.rb', line 56

def fetch_all(text = nil) # rubocop:disable Metrics/AbcSize
  io = IO.new($stdout.fcntl(::Fcntl::F_DUPFD), mode: "w:UTF-8")
  opts = options.each_with_object({}) do |(k, v), o|
    o[k.to_sym] = v unless k == "format"
  end
  Relaton.db.fetch_all(text, **opts).each do |doc|
    io.puts serialize(doc, options[:format])
  end
end

#mv(dir) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/relaton/cli/subcommand_db.rb', line 18

def mv(dir)
  new_path = File.expand_path dir
  path = Relaton.db.mv new_path
  if path
    File.write Cli::RelatonDb::DBCONF, path, encoding: "UTF-8"
    warn "Cache DB is moved to \"#{path}\""
  end
end