Class: Rails::Commands::Generate::Webhook
Instance Attribute Summary
#ctx, #options
Class Method Summary
collapse
Instance Method Summary
collapse
call
call, call_help, #initialize, options, prerequisite_task, run_prerequisites, subcommand, subcommand_registry
#hidden?, #hidden_feature
Instance Method Details
#call(args, _name) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/project_types/rails/commands/generate/webhook.rb', line 7
def call(args, _name)
selected_type = args.first
schema = ShopifyCli::AdminAPI::Schema.get(@ctx)
webhooks = schema.get_names_from_type('WebhookSubscriptionTopic')
unless selected_type && webhooks.include?(selected_type)
selected_type = CLI::UI::Prompt.ask(@ctx.message('rails.generate.webhook.select')) do |handler|
webhooks.each do |type|
handler.option(type) { type }
end
end
end
spin_group = CLI::UI::SpinGroup.new
spin_group.add(@ctx.message('rails.generate.webhook.selected', selected_type)) do |spinner|
Rails::Commands::Generate.run_generate(generate_command(selected_type), selected_type, @ctx)
spinner.update_title("{{green:#{selected_type}}} config/initializers/shopify_app.rb")
end
spin_group.wait
end
|
#generate_command(selected_type) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/project_types/rails/commands/generate/webhook.rb', line 30
def generate_command(selected_type)
parts = selected_type.downcase.split("_")
host = ShopifyCli::Project.current.env.host
selected_type = parts[0..-2].join("_") + "/" + parts[-1]
command = @ctx.windows? ? "ruby bin\\rails" : "bin/rails"
"#{command} g shopify_app:add_webhook -t #{selected_type} -a #{host}/webhooks/#{selected_type.downcase}"
end
|