Class: LocalCI::Flow
- Inherits:
-
Object
- Object
- LocalCI::Flow
- Defined in:
- lib/local_ci/flow.rb
Instance Attribute Summary collapse
-
#heading ⇒ Object
readonly
Returns the value of attribute heading.
-
#job_spinner ⇒ Object
readonly
Returns the value of attribute job_spinner.
Instance Method Summary collapse
-
#initialize(task:, heading:, parallel:, block:) ⇒ Flow
constructor
A new instance of Flow.
- #job(title, &block) ⇒ Object
- #pastel ⇒ Object
- #run(command) ⇒ Object
- #runner ⇒ Object
Constructor Details
#initialize(task:, heading:, parallel:, block:) ⇒ Flow
Returns a new instance of Flow.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/local_ci/flow.rb', line 8 def initialize(task:, heading:, parallel:, block:) @failures = [] @task = task @heading = heading @job_spinner = TTY::Spinner::Multi.new( "[:spinner] #{pastel.bold.blue(heading)}", format: :classic, success_mark: pastel.green("✓"), error_mark: pastel.red("✗"), style: { top: "", middle: " ", bottom: " " } ) klass = parallel ? Rake::MultiTask : Rake::Task @flow = klass.define_task(task) do @failures.each do |failure| failure.display end abort pastel.red("#{@heading} failed, see CI.log for more.") if @failures.any? end @flow.comment = heading Rake::Task[:local_ci].prerequisites << @task instance_exec(&block) end |
Instance Attribute Details
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
3 4 5 |
# File 'lib/local_ci/flow.rb', line 3 def heading @heading end |
#job_spinner ⇒ Object (readonly)
Returns the value of attribute job_spinner.
3 4 5 |
# File 'lib/local_ci/flow.rb', line 3 def job_spinner @job_spinner end |
Instance Method Details
#job(title, &block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/local_ci/flow.rb', line 39 def job(title, &block) task = "#{@task}:#{title}" spinner = job_spinner.register("[:spinner] #{title}") Rake::Task.define_task(task) do spinner.auto_spin start = Time.now instance_exec(&block) took = Time.now - start spinner.success("(#{took.round(2)}s)") rescue TTY::Command::ExitError => e spinner.error @failures << LocalCI::Failure.new( job: title, message: e. ) end @flow.prerequisites << task end |
#pastel ⇒ Object
5 |
# File 'lib/local_ci/flow.rb', line 5 def pastel = @pastel ||= Pastel.new |
#run(command) ⇒ Object
60 61 62 |
# File 'lib/local_ci/flow.rb', line 60 def run(command) runner.run command end |
#runner ⇒ Object
6 |
# File 'lib/local_ci/flow.rb', line 6 def runner = @runner ||= TTY::Command.new(output: Logger.new("ci.log")) |