Sha256: 5a57bb283e3b8572fdd1c1b7331f41b1f35cd80e931dd0a167d417f69a461e56

Contents?: true

Size: 1.36 KB

Versions: 25

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true
require "digest"
# This module provides classes for the Makit gem.
module Makit
  # This class provide methods for managing persistent data for the makit gem
  class Data
    attr_accessor :directory, :use_jsonks

    def initialize(attributes = {})
      @directory = attributes[:directory] || File.join(Dir.home, ".makit")
      @use_json = false
      attributes.each do |key, value|
        instance_variable_set("@#{key}", value) if self.class.method_defined?("#{key}=")
      end
    end

    # remove all data
    def clear
      # remove the data directory
      FileUtils.rm_rf(@directory) if Dir.exist?(@directory)
    end

    def get_content_id(item)
      # get the content id for the item
      bytes_string = item.to_proto.bytes.pack("C*")  # Convert the byte array to a string
      Digest::SHA256.hexdigest(bytes_string)
    end

    # save the content
    # data.save_content(git_version)
    def save(item)
      content_id = get_content_id(item)
      # save the content
      if @use_json
        # save the content to a json file
        File.open(File.join(@directory, "#{content_id}.json"), "w") do |file|
          file.write(item.to_json)
        end
      end
    end

    def get_content(content_id)
      nil
    end

    def self.gem_db_filename
      gem_data_directory = File.join(Dir.home, ".makit", "makit.db")
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
makit-0.0.27 lib/makit/data.rb
makit-0.0.5 lib/makit/data.rb
makit-0.0.4 lib/makit/data.rb
makit-0.0.3 lib/makit/data.rb
makit-0.0.2 lib/makit/data.rb