Class: SassListen::Forwarder

Inherits:
Object
  • Object
show all
Defined in:
lib/sass-listen/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Forwarder

Returns a new instance of Forwarder.


36
37
38
39
40
41
# File 'lib/sass-listen/cli.rb', line 36

def initialize(options)
  @options = options
  @logger = ::Logger.new(STDOUT)
  @logger.level = ::Logger::INFO
  @logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger


35
36
37
# File 'lib/sass-listen/cli.rb', line 35

def logger
  @logger
end

Instance Method Details

#startObject


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sass-listen/cli.rb', line 43

def start
  logger.info 'Starting listen...'
  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 = SassListen.to(
    directory,
    relative: relative,
    &callback)

  listener.start

  sleep 0.5 while listener.processing?
end