class Relaton::Cli::SubcommandDb

Public Instance Methods

clear() click to toggle source
# File lib/relaton/cli/subcommand_db.rb, line 29
def clear
  Relaton.db.clear
  warn "Cache DB is cleared"
end
create(dir = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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