Sha256: d7b306263c6a71d8c8669eb8845a6deee1ca9d35b3f376cbf1b87960f52a5e9b

Contents?: true

Size: 1.44 KB

Versions: 21

Compression:

Stored size: 1.44 KB

Contents

module Picky

  module Backends

    class Memory

      # Index data dumped in the text format.
      #
      # TODO Should this really be Memory::Text?
      #
      class Text < Basic

        # Uses the extension "txt".
        #
        def extension
          :txt
        end

        # The initial content before loading.
        #
        def initial
          raise "Can't have an initial content from text file. Use JSON or Marshal."
        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 token.
        #
        def retrieve
          id    = nil
          token = nil
          ::File.open(cache_path, 'r:utf-8') do |file|
            file.each_line do |line|
              id, token = line.split ?,, 2
              yield id, (token.chomp! || token)
            end
          end
        end

        #
        #
        def open &block
          create_directory cache_path
          ::File.open cache_path, 'w:utf-8', &block
        end


      end

    end

  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
picky-3.6.16 lib/picky/backends/memory/text.rb
picky-3.6.15 lib/picky/backends/memory/text.rb
picky-3.6.14 lib/picky/backends/memory/text.rb
picky-3.6.13 lib/picky/backends/memory/text.rb
picky-3.6.12 lib/picky/backends/memory/text.rb
picky-3.6.11 lib/picky/backends/memory/text.rb
picky-3.6.10 lib/picky/backends/memory/text.rb
picky-3.6.9 lib/picky/backends/memory/text.rb
picky-3.6.8 lib/picky/backends/memory/text.rb
picky-3.6.7 lib/picky/backends/memory/text.rb
picky-3.6.6 lib/picky/backends/memory/text.rb
picky-3.6.4 lib/picky/backends/memory/text.rb
picky-3.6.3 lib/picky/backends/memory/text.rb
picky-3.6.2 lib/picky/backends/memory/text.rb
picky-3.6.1 lib/picky/backends/memory/text.rb
picky-3.6.0 lib/picky/backends/memory/text.rb
picky-3.5.4 lib/picky/backends/memory/text.rb
picky-3.5.3 lib/picky/backends/memory/text.rb
picky-3.5.2 lib/picky/backends/memory/text.rb
picky-3.5.1 lib/picky/backends/memory/text.rb