Class: Monoz::Services::RunService

Inherits:
BaseService show all
Defined in:
lib/monoz/services/run_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(thor_instance) ⇒ RunService

Returns a new instance of RunService.



32
33
34
35
36
37
38
# File 'lib/monoz/services/run_service.rb', line 32

def initialize(thor_instance)
  super(thor_instance)
  @projects = nil
  @errors = []
  @warnings = []
  @command = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



30
31
32
# File 'lib/monoz/services/run_service.rb', line 30

def errors
  @errors
end

#warningsObject (readonly)

Returns the value of attribute warnings.



30
31
32
# File 'lib/monoz/services/run_service.rb', line 30

def warnings
  @warnings
end

Instance Method Details

#call(projects, *command) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/monoz/services/run_service.rb', line 40

def call(projects, *command)
  raise ArgumentError, "Missing command" if command.empty?

  @command = command
  if projects.is_a?(Monoz::ProjectCollection)
    @projects = projects.all
  elsif projects.is_a?(Monoz::Project)
    @projects = [projects]
  else
    raise "Invalid projects"
  end

  say "Running ", nil, false
  say command.join(" "), [:bold], false
  say " in #{@projects.map { |p| p.name }.to_sentence}:"

  say ""
  run_commands
  say ""

  if errors?
    say ""
    say "Error: The command ", :red
    say "#{command.join(" ")} ", [:red, :bold]
    say "failed to run in one or more project directories", [:red]
    exit(1)
  end
end

#errors?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/monoz/services/run_service.rb', line 73

def errors?
  @errors.any?
end

#success?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/monoz/services/run_service.rb', line 69

def success?
  !errors? && !warnings?
end

#warnings?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/monoz/services/run_service.rb', line 77

def warnings?
  @warnings.any?
end