Module: AsyncapiCable::RakeTasks

Extended by:
Rake::DSL
Defined in:
lib/asyncapi_cable/rake_tasks.rb

Overview

The Rails engine picks up lib/tasks/*.rake on its own; other hosts add

require "asyncapi_cable/rake_tasks"

to their Rakefile. Both routes end up here, so the task is defined once.

Class Method Summary collapse

Class Method Details

.install!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/asyncapi_cable/rake_tasks.rb', line 14

def self.install!
  return if Rake::Task.task_defined?("asyncapi_cable:generate")

  namespace :asyncapi_cable do
    desc "Generate AsyncAPI 3 documents for ActionCable channels. " \
         "FRAMEWORK=rspec|minitest|hybrid, PATTERN= comma-separated globs of declaration files."
    task :generate do
      support = AsyncapiCable::Generator::RakeTaskSupport
      framework = ENV.fetch("FRAMEWORK") { support.detect_test_framework }.to_s
      pattern = ENV.fetch("PATTERN") { support.default_pattern_for(framework) }

      # A subprocess so the host boots in its own test environment and the
      # suppressors are installed before anything else is required — same
      # arrangement as `openapi_ruby:generate`.
      script = support.generate_script(framework, pattern)
      command = "bundle exec ruby -e #{Shellwords.escape(script)}"

      puts "Generating AsyncAPI documents (#{framework})..."
      system(support.subprocess_env, command) || abort("AsyncAPI generation failed")
    end
  end
end