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



40
41
42
43
44
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 40

def add_webhook_job
  @job_file_name = job_file_name + '_job'
  @job_class_name = @job_file_name.classify
  template('webhook_job.rb', "app/jobs/#{@job_file_name}.rb")
end

#init_webhook_configObject



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

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",
    before: 'end'
  )
end

#inject_webhook_to_shopify_app_initializerObject



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

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