Class: CoffeeScriptRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/coffeescript/coffeescript_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(binary, dir, filter, dir_finder) ⇒ CoffeeScriptRunner

Returns a new instance of CoffeeScriptRunner.


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

def initialize(binary, dir, filter, dir_finder)
  @binary = binary
  @dir = dir
  @filter = filter
  @coffeescript_dir_finder = dir_finder

  @js_dir = dir + '/src'
end

Instance Method Details

#executeObject


16
17
18
19
20
21
22
23
24
25
# File 'lib/tasks/coffeescript/coffeescript_runner.rb', line 16

def execute
  output = []
  
  @coffee_dirs.each do |coffee_dir|
    js_dir = coffee_dir.sub '/coffee-', '/'
    output.push `#{@binary} --compile #{coffee_dir} --output #{js_dir}  2>&1`
  end
  
  return output.join "\n"
end

#is_configured?(all_files) ⇒ Boolean

TODO: Only return true if we can find the node binary

Returns:

  • (Boolean)

28
29
30
31
# File 'lib/tasks/coffeescript/coffeescript_runner.rb', line 28

def is_configured?(all_files)
  @coffee_dirs = (@coffeescript_dir_finder.find all_files).uniq
  return @coffee_dirs.length > 0
end

#nameObject


12
13
14
# File 'lib/tasks/coffeescript/coffeescript_runner.rb', line 12

def name
  return 'CoffeeScript'
end

#should_run?(modified_files) ⇒ Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/tasks/coffeescript/coffeescript_runner.rb', line 33

def should_run?(modified_files)
  return !(modified_files.detect { |file| @filter.filter(file) }).nil? || modified_files.include?(@config)
end