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.57 lib/makit/data.rb
makit-0.0.53 lib/makit/data.rb
makit-0.0.52 lib/makit/data.rb
makit-0.0.51 lib/makit/data.rb
makit-0.0.50 lib/makit/data.rb
makit-0.0.49 lib/makit/data.rb
makit-0.0.47 lib/makit/data.rb
makit-0.0.46 lib/makit/data.rb
makit-0.0.45 lib/makit/data.rb
makit-0.0.44 lib/makit/data.rb
makit-0.0.42 lib/makit/data.rb
makit-0.0.41 lib/makit/data.rb
makit-0.0.35 lib/makit/data.rb
makit-0.0.34 lib/makit/data.rb
makit-0.0.33 lib/makit/data.rb
makit-0.0.32 lib/makit/data.rb
makit-0.0.31 lib/makit/data.rb
makit-0.0.30 lib/makit/data.rb
makit-0.0.29 lib/makit/data.rb
makit-0.0.28 lib/makit/data.rb