Class: ClosureCompilerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/closure_compiler/closure_compiler_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(jar, dir, filter, config) ⇒ ClosureCompilerRunner

Returns a new instance of ClosureCompilerRunner.



3
4
5
6
7
8
9
10
# File 'lib/tasks/closure_compiler/closure_compiler_runner.rb', line 3

def initialize(jar, dir, filter, config)
  @jar = jar
  @config_file = dir + '/closure-compiler.yml'
  @dir = dir
  @filter = filter
  @config = config
  @output_file = ''
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tasks/closure_compiler/closure_compiler_runner.rb', line 16

def execute
  @config.reload
  conf = @config.conf
  
  @output_file = conf['js_output_file']
  
  input_params = ''

  conf.each do |param, value|
      
    if value.kind_of? Array
      
      value.each do |inner_value|
        input_params += " --#{param} \"#{inner_value}\""
      end
      
    elsif value.kind_of? Integer
      input_params += " --#{param} #{value}"
    else
      input_params += " --#{param} \"#{value}\""
    end
  end
  
  return `java -Xmx1024m -jar "#{@jar}" #{input_params} 2>&1`
end

#is_configured?(all_files) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/tasks/closure_compiler/closure_compiler_runner.rb', line 42

def is_configured?(all_files)
  return all_files.include?(@config_file)
end

#nameObject



12
13
14
# File 'lib/tasks/closure_compiler/closure_compiler_runner.rb', line 12

def name
  return 'Closure Compiler'
end

#should_run?(modified_files) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/tasks/closure_compiler/closure_compiler_runner.rb', line 46

def should_run?(modified_files)
  return !(modified_files.detect { |file| @filter.filter(file) && file != @dir + '/' + @output_file }).nil? || modified_files.include?(@config_file)
end