discourse/plugins/automation/spec/discourse_automation_helper.rb
Osama Sayegh 3d4faf3272
FEATURE: Merge discourse-automation (#26432)
Automation (previously known as discourse-automation) is now a core plugin.
2024-04-03 18:20:43 +03:00

37 lines
849 B
Ruby

# frozen_string_literal: true
require "rails_helper"
def capture_contexts(&blk)
DiscourseAutomation::CapturedContext.capture(&blk)
end
module DiscourseAutomation::CapturedContext
def self.add(context)
@contexts << context if @capturing
end
def self.capture
raise StandardError, "Nested capture is not supported" if @capturing
raise StandardError, "Expecting a block" if !block_given?
@capturing = true
@contexts = []
yield
@contexts
ensure
@capturing = false
end
end
DiscourseAutomation::Scriptable.add("something_about_us") do
script do |context|
DiscourseAutomation::CapturedContext.add(context)
nil
end
triggerables [DiscourseAutomation::Triggers::API_CALL]
end
DiscourseAutomation::Scriptable.add("nothing_about_us") do
triggerables [DiscourseAutomation::Triggers::API_CALL]
end