Sha256: 29ff3c5c4ff8bcb267ce8858b69137f021a37c016024061791460c9883326a93

Contents?: true

Size: 1.25 KB

Versions: 14

Compression:

Stored size: 1.25 KB

Contents

module Internals

  module Index
  
    module File
    
      # Index data dumped in the text format.
      #
      class Text < Basic
      
        # Uses the extension "txt".
        #
        def extension
          :txt
        end
        # Text files are used exclusively for
        # prepared data files.
        #
        def load
          raise "Can't load from text file. Use JSON or Marshal."
        end
        # Text files are used exclusively for
        # prepared data files. 
        #
        def dump hash
          raise "Can't dump to text file. Use JSON or Marshal."
        end
      
        # Retrieves prepared index data in the form
        # * id,data\n
        # * id,data\n
        # * id,data\n
        #
        # Yields an id string and a symbol token.
        #
        def retrieve
          id    = nil
          token = nil
          ::File.open(cache_path, 'r:binary') do |file|
            file.each_line do |line|
              id, token = line.split ?,, 2
              yield id, (token.chomp! || token).to_sym
            end
          end
        end
      
        #
        #
        def open_for_indexing &block
          ::File.open cache_path, 'w:binary', &block
        end
      
      
      end
    
    end
  
  end
  
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
picky-2.1.2 lib/picky/internals/index/file/text.rb
picky-2.1.1 lib/picky/internals/index/file/text.rb
picky-2.1.0 lib/picky/internals/index/file/text.rb
picky-2.0.0 lib/picky/internals/index/file/text.rb
picky-2.0.0.pre3 lib/picky/internals/index/file/text.rb
picky-2.0.0.pre2 lib/picky/internals/index/file/text.rb
picky-2.0.0.pre1 lib/picky/internals/index/file/text.rb
picky-1.5.4 lib/picky/internals/index/file/text.rb
picky-1.5.3 lib/picky/internals/index/file/text.rb
picky-1.5.2 lib/picky/internals/index/file/text.rb
picky-1.5.1 lib/picky/internals/index/file/text.rb
picky-1.5.0 lib/picky/internals/index/file/text.rb
picky-1.4.3 lib/picky/internals/index/file/text.rb
picky-1.4.2 lib/picky/internals/index/file/text.rb