Sha256: 45660afd3d677a4f44acd900018bc435daff088f51ee75abd7a1e490241ea1ca

Contents?: true

Size: 950 Bytes

Versions: 7

Compression:

Stored size: 950 Bytes

Contents

require 'listen'

module RevealCK
  module Commands
    # The idea of listening for file system changes and then
    # rebuilding slides.
    class ListenToRebuildSlides
      attr_reader :ui, :rebuild_method
      def initialize(ui, &block)
        @ui, @rebuild_method = ui, block
      end

      def run
        ::Listen.to('.', ignore: ignored_files_regex) do |mod, add, del|
          message_and_rebuild(mod, add, del)
        end.start
      end

      private

      def message_about_files(files, message)
        return if files.empty?
        file_names = files.join(', ')
        ui.message("#{message}: #{file_names}", :rebuild)
      end

      def ignored_files_regex
        /^slides\/.+$/
      end

      def message_and_rebuild(mod, add, del)
        message_about_files(mod, 'Modified')
        message_about_files(add, 'Added')
        message_about_files(del, 'Deleted')
        rebuild_method.call
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reveal-ck-3.0.1 lib/reveal-ck/commands/listen_to_rebuild_slides.rb
reveal-ck-3.0.0 lib/reveal-ck/commands/listen_to_rebuild_slides.rb
reveal-ck-0.6.2 lib/reveal-ck/commands/listen_to_rebuild_slides.rb
reveal-ck-0.6.1 lib/reveal-ck/commands/listen_to_rebuild_slides.rb
reveal-ck-0.6.0 lib/reveal-ck/commands/listen_to_rebuild_slides.rb
reveal-ck-0.5.1 lib/reveal-ck/commands/listen_to_rebuild_slides.rb
reveal-ck-0.5.0 lib/reveal-ck/commands/listen_to_rebuild_slides.rb