Class: Cch::Runner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Commands::FileSystem

#filter_files

Methods included from Commands::Shell

#backtiq_command, #system_command

Constructor Details

#initialize(name, options = {}) ⇒ Runner

Returns a new instance of Runner.



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

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

Instance Attribute Details

#commandObject

Returns the value of attribute command.



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

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#onObject

Returns the value of attribute on.



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

def on
  @on
end

#patternsObject (readonly)

Returns the value of attribute patterns.



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

def patterns
  @patterns
end

Class Method Details

.allObject



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

def self.all
  Cch.setup.runners.values
end

.where(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/cch/runner.rb', line 13

def self.where(options = {})
  runners = all
  runners = runners.select(&:on) if options[:on?]
  if (names = [options[:name]].flatten.compact).size > 0
    runners = runners.select { |r| names.include?(r.name) }
  end
  runners
end

Instance Method Details

#run(files) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/cch/runner.rb', line 33

def run(files)
  Cch.logger.info("running #{name.to_s.color(:black, :green)}")
  filtered_files = filter_files(files, patterns)
  return unless run?(filtered_files)

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

#run?(files) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/cch/runner.rb', line 41

def run?(files)
  Cch.logger.info("#{files.size.to_s.color(:yellow)} files=#{files}")
  files.size > 0
end

#watch(pattern, transform = nil) ⇒ Object



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

def watch(pattern, transform = nil)
  @patterns[pattern] = transform
end