Sha256: 15fd9bc914fac6cd6c87588ee81471165b2a00d6df642c895c6cce32d4cd1136

Contents?: true

Size: 912 Bytes

Versions: 18

Compression:

Stored size: 912 Bytes

Contents

# coding: utf-8
# frozen_string_literal: true

module Stealth
  class ServiceReply

    attr_accessor :recipient_id, :replies, :yaml_reply, :context

    def initialize(recipient_id:, yaml_reply:, context:, preprocessor: :none)
      @recipient_id = recipient_id
      @yaml_reply = yaml_reply
      @context = context

      processed_reply = case preprocessor
      when :erb
        preprocess_erb
      when :none
        @yaml_reply
      end

      @replies = load_replies(YAML.load(processed_reply))
    end

    private

      def load_replies(unstructured_replies)
        unstructured_replies.collect do |reply|
          Stealth::Reply.new(unstructured_reply: reply)
        end
      end

      def preprocess_erb
        begin
          ERB.new(yaml_reply).result(context)
        rescue NameError => e
          raise(Stealth::Errors::UndefinedVariable, e.message)
        end
      end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
stealth-1.1.6 lib/stealth/service_reply.rb
stealth-1.1.5 lib/stealth/service_reply.rb
stealth-1.1.4 lib/stealth/service_reply.rb
stealth-1.1.3 lib/stealth/service_reply.rb
stealth-1.1.2 lib/stealth/service_reply.rb
stealth-1.1.1 lib/stealth/service_reply.rb
stealth-1.1.0 lib/stealth/service_reply.rb
stealth-1.1.0.rc3 lib/stealth/service_reply.rb
stealth-1.1.0.rc2 lib/stealth/service_reply.rb
stealth-1.1.0.rc1 lib/stealth/service_reply.rb
stealth-1.0.4 lib/stealth/service_reply.rb
stealth-1.0.3 lib/stealth/service_reply.rb
stealth-1.0.2 lib/stealth/service_reply.rb
stealth-1.0.1 lib/stealth/service_reply.rb
stealth-1.0.0 lib/stealth/service_reply.rb
stealth-1.0.0.rc1 lib/stealth/service_reply.rb
stealth-1.0.0.pre2 lib/stealth/service_reply.rb
stealth-1.0.0.pre1 lib/stealth/service_reply.rb