Sha256: 7b912e1668d7dd0ed721265a8884a451af16d262717d55066b5c1003a396cd6f

Contents?: true

Size: 1 KB

Versions: 26

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "refinements/pathnames"

module SublimeTextKit
  module Metadata
    # Handles the creation, deletion, and recreation of metadata.
    class Handler
      using Refinements::Pathnames

      def self.with_project project_dir, metadata_dir
        new "sublime-project",
            serializer: Serializers::Project.new(Pathway[project_dir:, metadata_dir:])
      end

      def self.with_workspace project_dir, metadata_dir
        new "sublime-workspace",
            serializer: Serializers::Workspace.new(Pathway[project_dir:, metadata_dir:])
      end

      def initialize extension, serializer:
        @extension = extension
        @serializer = serializer
      end

      def create = path.exist? ? path : path.write(JSON.dump(serializer.to_h))

      def delete = path.exist? ? path.delete : path

      def recreate = delete && create

      private

      attr_reader :extension, :serializer

      def path = serializer.pathway.metadata_file(extension)
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
sublime_text_kit-15.2.1 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-15.2.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-15.1.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-15.0.3 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-15.0.2 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-15.0.1 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-15.0.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-14.2.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-14.1.2 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-14.1.1 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-14.1.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-14.0.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.5.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.4.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.3.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.2.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.1.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.0.1 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-13.0.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-12.3.2 lib/sublime_text_kit/metadata/handler.rb