Sha256: 4eb221c03c45c6980b43057e95a63d76ac46c3be38ee516cbc9106ed7e32d42e

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

require 'rbbt/association/database'

module Association
  def self.version_file(file, namespace)
    old_file, file = file, file.sub('NAMESPACE', namespace) if namespace and String === file
    old_file.annotate file if Path === old_file
    file
  end
  
  def self.open(file, options = nil, persist_options = nil)
    options = options.nil? ? {} : options.dup
    persist_options = persist_options.nil? ?  Misc.pull_keys(options, :persist)  : persist_options.dup 

    options = Misc.add_defaults options, :zipped => true, :monitor => {:desc => "Opening database #{Misc.fingerprint file}"}
    persist_options = Misc.add_defaults persist_options, :persist => true, :dir => Rbbt.var.associations
    persist = persist_options[:persist]

    file = version_file(file, options[:namespace]) if options[:namespace] and String === file
    file = file.call if Proc === file

    data = Persist.persist_tsv(file, "Association Database", options, persist_options) do |data|
      options = options.dup
      tsv = Association.database(file, options.merge(:persist => persist))
      tsv = tsv.to_double unless tsv.type == :double

      tsv.annotate data

      data.serializer = :double if data.respond_to? :serializer
      tsv.with_unnamed do
        tsv.with_monitor(options[:monitor]) do
          tsv.through do |k,v|
            data[k] = v
          end
        end
      end

      data
    end
    data.entity_options = options[:entity_options] if options[:entity_options]
    data
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rbbt-util-5.17.0 lib/rbbt/association/open.rb
rbbt-util-5.16.3 lib/rbbt/association/open.rb
rbbt-util-5.16.2 lib/rbbt/association/open.rb
rbbt-util-5.16.1 lib/rbbt/association/open.rb
rbbt-util-5.16.0 lib/rbbt/association/open.rb
rbbt-util-5.15.3 lib/rbbt/association/open.rb
rbbt-util-5.15.2 lib/rbbt/association/open.rb
rbbt-util-5.15.1 lib/rbbt/association/open.rb
rbbt-util-5.14.39 lib/rbbt/association/open.rb