Class: Cch::Runner

Inherits:
Object
  • Object
show all
Includes:
Commands::Shell
Defined in:
lib/cch/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands::Shell

#backtiq_command, #system_command

Constructor Details

#initialize(name) ⇒ Runner

Returns a new instance of Runner


8
9
10
11
12
13
# File 'lib/cch/runner.rb', line 8

def initialize(name)
  @name = name
  @command = "bundle exec #{@name} %{files}"
  @on = false
  @patterns = []
end

Instance Attribute Details

#commandObject

Returns the value of attribute command


6
7
8
# File 'lib/cch/runner.rb', line 6

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/cch/runner.rb', line 5

def name
  @name
end

#onObject

Returns the value of attribute on


6
7
8
# File 'lib/cch/runner.rb', line 6

def on
  @on
end

#patternsObject (readonly)

Returns the value of attribute patterns


5
6
7
# File 'lib/cch/runner.rb', line 5

def patterns
  @patterns
end

Instance Method Details

#filter_files(files) ⇒ Object


28
29
30
31
32
33
# File 'lib/cch/runner.rb', line 28

def filter_files(files)
  filtered_files = patterns.flat_map { |pattern| files.grep(pattern) }
  puts "=> filtered_files='#{filtered_files}'" if Setup.debug

  filtered_files.sort.uniq.select { |f| File.exist?(f) }
end

#run(files) ⇒ Object


19
20
21
22
23
24
25
26
# File 'lib/cch/runner.rb', line 19

def run(files)
  puts "=> running #{@name.to_s.color(:black, :green)}"
  files = filter_files(files)
  puts "=> #{files.size.to_s.color(:yellow)} files=#{files}"
  return unless run?(files)

  system_command(@command % { files: files.join(' ') })
end

#run?(files) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/cch/runner.rb', line 35

def run?(files)
  files.size > 0
end

#watch(pattern) ⇒ Object


15
16
17
# File 'lib/cch/runner.rb', line 15

def watch(pattern)
  @patterns << pattern
end