Sha256: 0242d5bbe645ff193f3d39d8e4ba97f527aa70fd47fc9e96812964c77989bfce
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true module ForemanWebhooks module Renderer module Scope class WebhookTemplate < ::Foreman::Renderer::Scope::Template extend ApipieDSL::Class apipie :class, 'Macros related to Webhook payload customization' do name 'Webhook Template' sections only: %w[all webhooks] end def initialize(**args) super @defaults = { event_name: @event_name, webhook_id: @webhook_id, context: @context } end apipie :method, 'Creates final payload' do required :hash, Hash, 'Key=value object with with data that should be present in payload' keyword :with_defaults, [true, false], 'If set to true, adds default entries to the payload', default: true returns String, 'JSON string with the final payload' example 'payload({ id: @object.id, name: @object.name }) #=> "{ "id": 1, "name": "host.example.com", "context": { ... }, "event_name": "host_created.event.foreman" }"' end def payload(hash, with_defaults: true) hash.merge!(@defaults) if with_defaults hash.to_json end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foreman_webhooks-0.0.1 | app/lib/foreman_webhooks/renderer/scope/webhook_template.rb |