# class Listen::Forwarder

### Attributes

logger[R]

### Public Class Methods

new(options) click to toggle source

    # File lib/listen/cli.rb, line 42
    def initialize(options)
      @options = options
      @logger = Logger.new(STDOUT)
      @logger.level = Logger::INFO
      @logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
    end

### Public Instance Methods

start() click to toggle source

    # File lib/listen/cli.rb, line 49
    def start
      logger.info 'Starting listen...'
      address = @options[:forward]
      directory = @options[:directory]
      relative = @options[:relative]
      callback = proc do |modified, added, removed|
        if @options[:verbose]
          logger.info "+ #{added}" unless added.empty?
          logger.info "- #{removed}" unless removed.empty?
          logger.info "> #{modified}" unless modified.empty?
        end
      end

      listener = Listen.to(
        directory,
        forward_to: address,
        relative: relative,
        &callback)

      listener.start

      sleep 0.5 while listener.listen?
    end