Sha256: 2bb36f4157b7573101034b37da4345699f4c1a205618411d4851b293c0278902

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# typed: strict
# frozen_string_literal: true

module Bhook
  class Workspace
    extend T::Sig

    sig { params(src_path: String, out_path: String, theme_path: String).void }
    def initialize(src_path, out_path, theme_path)
      @src_path = T.let(Pathname.new(src_path).expand_path, Pathname)
      @out_path = T.let(Pathname.new(out_path).expand_path, Pathname)
      @theme = T.let(Theme.new(theme_path), Bhook::Theme)
    end

    sig { void }
    def process!
      root_dir.write!(@theme)
      L.info 'Done!'
    end

    sig { void }
    def watch!
      process!

      L.info "Watching: #{@src_path} for changes..."
      listener = Listen.to(@src_path.to_s, File.join(@src_path.to_s, '.git')) do |_modified, _added, _removed|
        L.info 'Detected changes...'
        process!
      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_root_directory(@src_path, @out_path)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bhook-0.2.2 lib/bhook/workspace.rb
bhook-0.2.1 lib/bhook/workspace.rb
bhook-0.2.0 lib/bhook/workspace.rb