Sha256: a74fb8589b670abc4b3c260f5311777d63c2c45b90164f31c63a535d60be6dba

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require_relative 'base'
require_relative '../../engine/tokyocabinet'

module TKAdapter 
  include TSVAdapter
  def self.extended(obj)
    obj.extend TSVAdapter
    obj
  end
end

module Persist
  def self.open_tokyocabinet(path, write, serializer = nil, tokyocabinet_class = TokyoCabinet::HDB)
    write = true unless File.exist? path

    FileUtils.mkdir_p File.dirname(path) unless File.exist?(File.dirname(path))

    database = ScoutCabinet.open(path, write, tokyocabinet_class)

    database.extend TKAdapter
    database.serializer ||= TSVAdapter.serializer_module(serializer)

    database
  end
end

Persist.save_drivers[:HDB] = proc do |file, content|
  if ScoutCabinet === content
    Open.mv(content.persistence_path, file)
    content.persistence_path = file
    content
  else
    data = ScoutCabinet.open(file, true, "HDB")
    content.annotate(data)
    data.extend TKAdapter
    data.merge!(content)
    data
  end
end

Persist.load_drivers[:HDB] = proc do |file| 
  data = ScoutCabinet.open(file, false, "HDB")
  data.extend TKAdapter unless TKAdapter === data
  data
end

Persist.save_drivers[:BDB] = proc do |file, content|
  if ScoutCabinet === content
    Open.mv(content.persistence_path, file)
    content.persistence_path = file
    content
  else
    data = ScoutCabinet.open(file, true, "BDB")
    content.annotate(data)
    data.extend TKAdapter
    data.merge!(content)
    data
  end
end

Persist.load_drivers[:BDB] = proc do |file| 
  data = ScoutCabinet.open(file, false, "BDB")
  data.extend TKAdapter unless TKAdapter === data
  data
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scout-gear-10.7.1 lib/scout/persist/tsv/adapter/tokyocabinet.rb
scout-gear-10.7.0 lib/scout/persist/tsv/adapter/tokyocabinet.rb