Class: ShopifyCLI::Theme::Syncer::ErrorReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/theme/syncer/error_reporter.rb

Overview

ShopifyCLI::Theme::Syncer::ErrorReporter allows delaying log of errors, mainly to not break the progress bar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx) ⇒ ErrorReporter

Returns a new instance of ErrorReporter.



13
14
15
16
17
18
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 13

def initialize(ctx)
  @ctx = ctx
  @has_any_error = false
  @delay_errors = false
  @delayed_errors = []
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



11
12
13
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 11

def ctx
  @ctx
end

#delayed_errorsObject (readonly)

Returns the value of attribute delayed_errors.



11
12
13
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 11

def delayed_errors
  @delayed_errors
end

Instance Method Details

#disable!Object



20
21
22
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 20

def disable!
  @delay_errors = true
end

#enable!Object



24
25
26
27
28
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 24

def enable!
  @delay_errors = false
  @delayed_errors.each { |error| report(error) }
  @delayed_errors.clear
end

#has_any_error?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 39

def has_any_error?
  @has_any_error
end

#report(error_message) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/shopify_cli/theme/syncer/error_reporter.rb', line 30

def report(error_message)
  if @delay_errors
    @delayed_errors << error_message
  else
    @has_any_error = true
    @ctx.error(error_message)
  end
end