Sha256: afad0dad407d5a880acfdc0dea0f3487da89947cc43a9bf096e4af03cd785611

Contents?: true

Size: 1.15 KB

Versions: 13

Compression:

Stored size: 1.15 KB

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

        # Dump JSON into the cache file.
        #
        # TODO Ask MultiJson people to add IO option:
        # MultiJson.encode(object, out_file)
        #
        def dump_json internal
          ::File.open(cache_path, 'w') do |out_file|
            # MultiJson.encode internal, out_file
            out_file.write MultiJson.encode internal
          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

13 entries across 13 versions & 1 rubygems

Version Path
picky-4.6.0 lib/picky/backends/memory/json.rb
picky-4.5.12 lib/picky/backends/memory/json.rb
picky-4.5.11 lib/picky/backends/memory/json.rb
picky-4.5.10 lib/picky/backends/memory/json.rb
picky-4.5.9 lib/picky/backends/memory/json.rb
picky-4.5.8 lib/picky/backends/memory/json.rb
picky-4.5.7 lib/picky/backends/memory/json.rb
picky-4.5.6 lib/picky/backends/memory/json.rb
picky-4.5.5 lib/picky/backends/memory/json.rb
picky-4.5.4 lib/picky/backends/memory/json.rb
picky-4.5.3 lib/picky/backends/memory/json.rb
picky-4.5.2 lib/picky/backends/memory/json.rb
picky-4.5.1 lib/picky/backends/memory/json.rb