Class: Cch::Runner
- Inherits:
-
Object
- Object
- Cch::Runner
- Includes:
- Commands::FileSystem, Commands::Shell
- Defined in:
- lib/cch/runner.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#on ⇒ Object
Returns the value of attribute on.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run(files) ⇒ Object
- #run?(files) ⇒ Boolean
- #watch(pattern, transform = nil) ⇒ Object
Methods included from Commands::FileSystem
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, = {}) @name = name @command = "bundle exec #{options[:gem] || name} %{files}" @on = false @patterns = {} end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
7 8 9 |
# File 'lib/cch/runner.rb', line 7 def command @command end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/cch/runner.rb', line 6 def name @name end |
#on ⇒ Object
Returns the value of attribute on.
7 8 9 |
# File 'lib/cch/runner.rb', line 7 def on @on end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
6 7 8 |
# File 'lib/cch/runner.rb', line 6 def patterns @patterns end |
Class Method Details
.all ⇒ Object
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( = {}) runners = all runners = runners.select(&:on) if [:on?] if (names = [[: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
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 |