Class: Cch::Runner
- Inherits:
-
Object
- Object
- Cch::Runner
- Includes:
- Commands::FileSystem, Commands::Shell
- Defined in:
- lib/cch/runner.rb
Class Attribute Summary collapse
-
.runners ⇒ Object
Returns the value of attribute runners.
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
- .all ⇒ Object
- .configure(runner, options = {}) {|@runners.fetch(runner)| ... } ⇒ Object
- .run(runners) ⇒ Object
- .where(query = {}) ⇒ Object
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.
37 38 39 40 41 42 |
# File 'lib/cch/runner.rb', line 37 def initialize(name, = {}) @name = name @command = "bundle exec #{[:gem] || name} %{files}" @on = false @patterns = {} end |
Class Attribute Details
.runners ⇒ Object
Returns the value of attribute runners.
7 8 9 |
# File 'lib/cch/runner.rb', line 7 def runners @runners end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
35 36 37 |
# File 'lib/cch/runner.rb', line 35 def command @command end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/cch/runner.rb', line 34 def name @name end |
#on ⇒ Object
Returns the value of attribute on.
35 36 37 |
# File 'lib/cch/runner.rb', line 35 def on @on end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
34 35 36 |
# File 'lib/cch/runner.rb', line 34 def patterns @patterns end |
Class Method Details
.all ⇒ Object
19 20 21 |
# File 'lib/cch/runner.rb', line 19 def all runners.values end |
.configure(runner, options = {}) {|@runners.fetch(runner)| ... } ⇒ Object
9 10 11 12 13 |
# File 'lib/cch/runner.rb', line 9 def configure(runner, = {}) @runners ||= {} @runners[runner] = Runner.new(runner, ) yield @runners.fetch(runner) if block_given? end |
.run(runners) ⇒ Object
15 16 17 |
# File 'lib/cch/runner.rb', line 15 def run(runners) Array(runners).each { |runner| @runners.fetch(runner).on = true } end |
.where(query = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/cch/runner.rb', line 23 def where(query = {}) runners = all runners = runners.select(&:on) if query[:on?] if (names = [query[:name]].flatten.compact).any? runners = runners.select { |r| names.include?(r.name.to_s) } end runners end |
Instance Method Details
#run(files) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/cch/runner.rb', line 48 def run(files) files = filter_files(files, patterns) return unless run?(files) system_command(command % { files: files.join(' ') }) end |
#run?(files) ⇒ Boolean
55 56 57 58 59 60 |
# File 'lib/cch/runner.rb', line 55 def run?(files) = "running #{name.to_s.color(:black, :green)}" << " for #{files.size.to_s.color(:yellow)} files=#{files}" Cch.logger.info() files.any? end |
#watch(pattern, transform = nil) ⇒ Object
44 45 46 |
# File 'lib/cch/runner.rb', line 44 def watch(pattern, transform = nil) @patterns[pattern] = transform end |