Prechádzať zdrojové kódy

EventFormattingAgent: Partial revert: Do not include "agent" to payload.

Akinori MUSHA 10 rokov pred
rodič
commit
307ef15b8e

+ 0 - 7
app/models/agent.rb

@@ -402,12 +402,5 @@ class AgentDrop < Liquid::Drop
     def to_liquid
       AgentDrop.new(self)
     end
-
-    def to_h
-      drop = to_liquid
-      AgentDrop.public_instance_methods(false).each_with_object({}) { |attr, hash|
-        hash[attr.to_s] = drop.__send__(attr)
-      }
-    end
   end
 end

+ 1 - 1
app/models/agents/event_formatting_agent.rb

@@ -106,7 +106,7 @@ module Agents
 
     def receive(incoming_events)
       incoming_events.each do |event|
-        payload = perform_matching({ 'agent' => event.agent.to_h }.merge(event.payload))
+        payload = perform_matching(event.payload)
         opts = interpolated(EventDrop.new(event, payload))
         formatted_event = opts['mode'].to_s == "merge" ? event.payload.dup : {}
         formatted_event.merge! opts['instructions']

+ 2 - 9
spec/models/agents/event_formatting_agent_spec.rb

@@ -8,8 +8,7 @@ describe Agents::EventFormattingAgent do
             :instructions => {
                 :message => "Received {{content.text}} from {{content.name}} .",
                 :subject => "Weather looks like {{conditions}} according to the forecast at {{pretty_date.time}}",
-                :agent_type => "{{agent.type}}",
-                :agent_type_via_matching => "{{agent_info.type}}",
+                :agent => "{{agent.type}}",
             },
             :mode => "clean",
             :matchers => [
@@ -18,11 +17,6 @@ describe Agents::EventFormattingAgent do
                     :regexp => "\\A(?<time>\\d\\d:\\d\\d [AP]M [A-Z]+)",
                     :to => "pretty_date",
                 },
-                {
-                    :path => "{{agent.type}}",
-                    :regexp => "\\A(?<type>.*)\\z",
-                    :to => "agent_info",
-                },
             ],
             :skip_created_at => "false"
         }
@@ -70,13 +64,12 @@ describe Agents::EventFormattingAgent do
     it "should handle Liquid templating in instructions" do
       @checker.receive([@event])
       Event.last.payload[:message].should == "Received Some Lorem Ipsum from somevalue ."
-      Event.last.payload[:agent_type].should == "WeatherAgent"
+      Event.last.payload[:agent].should == "WeatherAgent"
     end
 
     it "should handle matchers and Liquid templating in instructions" do
       @checker.receive([@event])
       Event.last.payload[:subject].should == "Weather looks like someothervalue according to the forecast at 10:00 PM EST"
-      Event.last.payload[:agent_type_via_matching].should == "WeatherAgent"
     end
 
     it "should allow escaping" do