Sha256: 67c72d384eea49a19c76d86b034ddb0f30ebfc48bb4be3e9d2184b7a4a93391a

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module Bhook
  class Workspace
    extend T::Sig

    sig { params(src_path: String, out_path: String).void }
    def initialize(src_path, out_path)
      @src_path = src_path
      @out_path = out_path
    end

    sig { void }
    def process!
      root = root_dir
      root.write!(@out_path)
    end

    sig { void }
    def watch!
      process!
      puts
      puts "Watching #{@src_path} for changes..."
      listener = Listen.to(@src_path, File.join(@src_path, '.git')) do |_modified, _added, _removed|
        process!
        puts "-----\n"
      end
      listener.start
      sleep
    end

    sig { returns(T::Array[MdFile]) }
    def all_md_files
      root_dir.all_md_files
    end

    private

    sig { returns(Bhook::Directory) }
    def root_dir
      Directory.new(Pathname.new(@src_path))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bhook-0.1.0 lib/bhook/workspace.rb