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



36
37
38
39
40
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 36

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

#init_webhook_configObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 11

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



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/shopify_app/add_webhook/add_webhook_generator.rb', line 22

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