Sha256: 1373a039789a55b2280954877ffa7d337f37b73be0fe6a60419b40f63fd062b7

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

module Intent
  module Core
    class Projects
      attr_reader :list
      attr_reader :ledger_path

      def initialize(db_path)
        @ledger_path = db_path
        @list = List.new(db_path)
      end

      def all
        list.by_not_done
      end

      def all_tokens
        all.map { |item| item.projects.first }.uniq
      end

      def linked_directory(path)
        all.find { |item| item.text == path && ['repository', 'directory'].include?(item.tags[:is]) }
      end

      def sync!
        ledger_file = File.basename(ledger_path)

        if repo.status.changed?(ledger_file)
          repo.add(ledger_file)
          repo.commit("Synchronizing projects [#{Time.new}]")
          repo.push
          true # Result:OK
        else
          false # Result::NO_CHANGES
        end
      end

      def add_directory!(path, project, id, computer)
        record = Record.new([
          Date.today,
          path,
          project,
          "is:directory",
          "id:#{id}",
          "computer:#{computer}"
        ].join(' '))

        @list.append(record)
        @list.save!
      end

      private

      def repo
        @repo ||= Git.open(Env.documents_dir, :log => Logger.new(STDERR, level: Logger::INFO))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
intent-0.8.1 lib/intent/core/projects.rb
intent-0.8.0 lib/intent/core/projects.rb