Sha256: 3a8a1b2ea277447632326ed109f162c4f68b426dbe181ef26e3094b59169c057

Contents?: true

Size: 1.25 KB

Versions: 21

Compression:

Stored size: 1.25 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

21 entries across 21 versions & 1 rubygems

Version Path
foreman_webhooks-4.0.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.2.3 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.2.2 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.1.1 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.2.1 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.2.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.1.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.0.5 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-2.0.3 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.0.4 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-2.0.2 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.0.3 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.0.2 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.0.1 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-2.0.1 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-3.0.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-2.0.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-1.1.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-1.0.0 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb
foreman_webhooks-0.0.3 app/lib/foreman_webhooks/renderer/scope/webhook_template.rb