Sha256: f0acacf7cb98af016220983277acdf623704e58a28e795ebc20d5fa074f2d8d5

Contents?: true

Size: 1.8 KB

Versions: 66

Compression:

Stored size: 1.8 KB

Contents

module Picky

  module Backends

    class File

      # Base class for all file-based index files.
      #
      # Provides necessary helper methods for its
      # subclasses.
      # Not directly useable, as it does not provide
      # dump/load methods.
      #
      class Basic

        include Helpers::File

        attr_reader :cache_path,  # This index file's location.
                    :mapping_file # The index file's mapping file (loaded into memory for quick access).

        # An index cache takes a path, without file extension,
        # which will be provided by the subclasses.
        #
        def initialize cache_path, options = {}
          @cache_path = "#{cache_path}.file.#{extension}"

          # This is the mapping file with the in-memory hash for the
          # file position/offset mappings.
          #
          @mapping_file = Memory::JSON.new "#{cache_path}.file_mapping.#{extension}"

          @empty   = options[:empty]
          @initial = options[:initial]
        end

        # The default extension for index files is "index".
        #
        def extension
          :index
        end

        # The empty index that is used for putting the index
        # together before it is saved into the files.
        #
        def empty
          @empty && @empty.clone || {}
        end

        # The initial content before loading.
        #
        # Note: We could also load the mapping file
        #       as in #load.
        #
        def initial
          @initial && @initial.clone || {}
        end

        # Deletes the file.
        #
        def delete
          mapping_file.delete

          `rm -Rf #{cache_path}`
        end

        #
        #
        def to_s
          "#{self.class}(#{cache_path},#{mapping_file.cache_path})"
        end

      end

    end

  end

end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
picky-4.12.1 lib/picky/backends/file/basic.rb
picky-4.12.0 lib/picky/backends/file/basic.rb
picky-4.11.3 lib/picky/backends/file/basic.rb
picky-4.11.2 lib/picky/backends/file/basic.rb
picky-4.11.1 lib/picky/backends/file/basic.rb
picky-4.11.0 lib/picky/backends/file/basic.rb
picky-4.10.0 lib/picky/backends/file/basic.rb
picky-4.9.0 lib/picky/backends/file/basic.rb
picky-4.8.1 lib/picky/backends/file/basic.rb
picky-4.8.0 lib/picky/backends/file/basic.rb
picky-4.7.0 lib/picky/backends/file/basic.rb
picky-4.6.6 lib/picky/backends/file/basic.rb
picky-4.6.5 lib/picky/backends/file/basic.rb
picky-4.6.4 lib/picky/backends/file/basic.rb
picky-4.6.3 lib/picky/backends/file/basic.rb
picky-4.6.2 lib/picky/backends/file/basic.rb
picky-4.6.1 lib/picky/backends/file/basic.rb
picky-4.6.0 lib/picky/backends/file/basic.rb
picky-4.5.12 lib/picky/backends/file/basic.rb
picky-4.5.11 lib/picky/backends/file/basic.rb