Class: Sasquatch::Quatcher

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/quatch/quatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger, #print_line

Constructor Details

#initialize(*args) ⇒ Quatcher

Returns a new instance of Quatcher.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/quatch/quatcher.rb', line 13

def initialize *args

  @options = parse_options args

  @listeners = []

  @compiler = Compiler.new('.min.js')

  @options[:files].each do |file|

    @listeners << Listener.new(file, &file_changed)

  end

end

Instance Attribute Details

#compilerObject (readonly)

Returns the value of attribute compiler.



11
12
13
# File 'lib/quatch/quatcher.rb', line 11

def compiler
  @compiler
end

#listenersObject (readonly)

Returns the value of attribute listeners.



11
12
13
# File 'lib/quatch/quatcher.rb', line 11

def listeners
  @listeners
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/quatch/quatcher.rb', line 11

def options
  @options
end

Instance Method Details

#file_changedObject



29
30
31
32
33
34
35
36
37
# File 'lib/quatch/quatcher.rb', line 29

def file_changed

  Proc.new do |modified_file, file, files|

    @compiler.compile(files, file)

    logger "Sasquatch has detected a change to #{modified_file}, recompiling..."
  end
end

#parse_options(argv) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/quatch/quatcher.rb', line 39

def parse_options(argv)
  params = {}
  parser = OptionParser.new

  parser.on("-n") { params[:line_numbering_style] ||= :all_lines         }
  parser.on("-b") { params[:line_numbering_style]   = :significant_lines }
  parser.on("-s") { params[:squeeze_extra_newlines] = true               }

  params[:files] = parser.parse(argv)

  params
end