Sha256: db36aacb5e96203d400b6de1c8c6af8c3811d04a9f598c3c5e98d79b014ada14

Contents?: true

Size: 813 Bytes

Versions: 8

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

require "pathname"
require "rexml/document"

module SublimeTextKit
  module Snippets
    class Collector
      DEFAULT_USER_PATH = "Library/Application Support/Sublime Text 3/Packages/User"

      def initialize model: Snippet, user_path: DEFAULT_USER_PATH, environment: ENV
        @model = model
        @user_path = user_path
        @environment = environment
      end

      def home_path
        Pathname environment.fetch("HOME")
      end

      def root_path
        home_path.join user_path
      end

      def call
        root_path.glob("*.sublime-snippet")
                 .map { |path| model.new REXML::Document.new(path.read) }
                 .sort_by(&:description)
      end

      private

      attr_reader :model, :user_path, :environment
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sublime_text_kit-10.0.2 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-10.0.1 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-10.0.0 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-9.6.0 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-9.5.0 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-9.4.0 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-9.3.0 lib/sublime_text_kit/snippets/collector.rb
sublime_text_kit-9.2.0 lib/sublime_text_kit/snippets/collector.rb