Sha256: 50bd56914fbfadc43885853abf459d5631efa13b3985317620d903af7f0500a4

Contents?: true

Size: 1022 Bytes

Versions: 13

Compression:

Stored size: 1022 Bytes

Contents

# frozen_string_literal: true

require "refinements/pathname"

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

      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

13 entries across 13 versions & 1 rubygems

Version Path
sublime_text_kit-17.6.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.5.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.4.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.3.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.2.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.1.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.0.1 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-17.0.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-16.5.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-16.3.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-16.2.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-16.1.0 lib/sublime_text_kit/metadata/handler.rb
sublime_text_kit-16.0.0 lib/sublime_text_kit/metadata/handler.rb