Module: ShopifyCLI::ReportingConfigurationController

Defined in:
lib/shopify_cli/reporting_configuration_controller.rb

Class Method Summary collapse

Class Method Details

.check_or_prompt_report_automatically(source: :usage, prompt: true, context: ShopifyCLI::Context.new) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shopify_cli/reporting_configuration_controller.rb', line 25

def self.check_or_prompt_report_automatically(source: :usage, prompt: true, context: ShopifyCLI::Context.new)
  return false if ShopifyCLI::Environment.development? || ShopifyCLI::Environment.test?

  # If the terminal is not interactive we can't prompt the user.
  return false unless ShopifyCLI::Environment.interactive?

  if reporting_prompted?
    reporting_enabled?
  elsif prompt
    prompt_user(context: context, source: source)
  else
    false
  end
end

.enable_reporting(enabled) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/shopify_cli/reporting_configuration_controller.rb', line 3

def self.enable_reporting(enabled)
  ShopifyCLI::Config.set(
    Constants::Config::Sections::Analytics::NAME,
    Constants::Config::Sections::Analytics::Fields::ENABLED,
    enabled
  )
end

.prompt_user(context:, source:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shopify_cli/reporting_configuration_controller.rb', line 40

def self.prompt_user(context:, source:)
  enable_automatic_tracking = CLI::UI::Prompt.ask(
    context.message("core.analytics.enable_prompt.#{source}.question")
  ) do |handler|
    handler.option(context.message("core.analytics.enable_prompt.#{source}.yes")) { |_| true }
    handler.option(context.message("core.analytics.enable_prompt.#{source}.no")) { |_| false }
  end

  ShopifyCLI::Config.set(
    Constants::Config::Sections::Analytics::NAME,
    Constants::Config::Sections::Analytics::Fields::ENABLED,
    enable_automatic_tracking
  )

  message = if enable_automatic_tracking
    context.message("core.reporting.turned_on_message")
  else
    context.message("core.reporting.turned_off_message", ShopifyCLI::TOOL_NAME)
  end
  context.puts(message)

  enable_automatic_tracking
end

.reporting_enabled?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/shopify_cli/reporting_configuration_controller.rb', line 17

def self.reporting_enabled?
  ShopifyCLI::Config.get_bool(
    Constants::Config::Sections::Analytics::NAME,
    Constants::Config::Sections::Analytics::Fields::ENABLED,
    default: false
  )
end

.reporting_prompted?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/shopify_cli/reporting_configuration_controller.rb', line 11

def self.reporting_prompted?
  ShopifyCLI::Config.get_section(Constants::Config::Sections::Analytics::NAME).key?(
    Constants::Config::Sections::Analytics::Fields::ENABLED
  )
end