Class: ShopifyApp::Generators::AddWebhookGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/shopify_app/add_webhook/add_webhook_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_webhook_jobObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 41

def add_webhook_job
  namespace = ShopifyApp.configuration.webhook_jobs_namespace
  @job_file_name = if namespace.present?
    "#{namespace}/#{job_file_name}_job"
  else
    "#{job_file_name}_job"
  end
  @job_class_name = @job_file_name.classify
  template("webhook_job.rb", "app/jobs/#{@job_file_name}.rb")
end

#init_webhook_configObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 16

def init_webhook_config
  initializer = load_initializer
  return if initializer.include?("config.webhooks")

  inject_into_file(
    "config/initializers/shopify_app.rb",
    "  config.webhooks = [\n  ]\n",
    after: /ShopifyApp\.configure.*\n/,
  )
end

#inject_webhook_to_shopify_app_initializerObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 27

def inject_webhook_to_shopify_app_initializer
  inject_into_file(
    "config/initializers/shopify_app.rb",
    webhook_config,
    after: "config.webhooks = [",
  )

  initializer = load_initializer

  unless initializer.include?(webhook_config)
    shell.say("Error adding webhook to config. Add this line manually: #{webhook_config}", :red)
  end
end