Sha256: b9e193f15ee22d1c74d525371fb8dbd29d99dccfb713d9e0be6c4dd17a82942a

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

module Picky

  module Backends

    class Memory

      # Memory-based index files dumped in the JSON format.
      #
      class JSON < Basic

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

        # Loads the index hash from json format.
        #
        def load
          MultiJson.decode ::File.open(cache_path, 'r') # , symbolize_keys: true # TODO Symbols.
        end

        # Dumps the index internal backend in json format.
        #
        def dump internal
          create_directory cache_path
          dump_json internal
        end

        #
        #
        def dump_json internal
          ::File.open(cache_path, 'w') do |out_file|
            MultiJson.encode internal, out_file
          end
        end

        # A json file does not provide retrieve functionality.
        #
        def retrieve
          raise "Can't retrieve from JSON file. Use text file."
        end

      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-4.5.0 lib/picky/backends/memory/json.rb