## Fluentd## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#require'fluent/event'require'fluent/time'moduleFluentmoduleTestmoduleDrivermoduleEventFeederdefinitialize(klass,opts: {},&block)super@default_tag=nil@feed_method=nilenddefrun(default_tag: nil,**kwargs,&block)@feed_method=if@instance.respond_to?(:filter_stream):filter_streamelse:emit_eventsendifdefault_tag@default_tag=default_tagendsuper(**kwargs,&block)enddeffeed_to_plugin(tag,es)@instance.__send__(@feed_method,tag,es)end# d.run do# d.feed('tag', time, {record})# d.feed('tag', [ [time, {record}], [time, {record}], ... ])# d.feed('tag', es)# end# d.run(default_tag: 'tag') do# d.feed({record})# d.feed(time, {record})# d.feed([ [time, {record}], [time, {record}], ... ])# d.feed(es)# enddeffeed(*args)caseargs.sizewhen1raiseArgumentError,"tag not specified without default_tag"unless@default_tagcaseargs.firstwhenFluent::EventStreamfeed_to_plugin(@default_tag,args.first)whenArrayfeed_to_plugin(@default_tag,ArrayEventStream.new(args.first))whenHashrecord=args.firsttime=Fluent::EventTime.nowfeed_to_plugin(@default_tag,OneEventStream.new(time,record))elseraiseArgumentError,"unexpected events object (neither event(Hash), EventStream nor Array): #{args.first.class}"endwhen2ifargs[0].is_a?(String)&&(args[1].is_a?(Array)||args[1].is_a?(Fluent::EventStream))tag,es=argses=ArrayEventStream.new(es)ifes.is_a?(Array)feed_to_plugin(tag,es)elsif@default_tag&&(args[0].is_a?(Fluent::EventTime)||args[0].is_a?(Integer))&&args[1].is_a?(Hash)time,record=argsfeed_to_plugin(@default_tag,OneEventStream.new(time,record))elseraiseArgumentError,"unexpected values of argument: #{args[0].class}, #{args[1].class}"endwhen3tag,time,record=argsiftag.is_a?(String)&&(time.is_a?(Fluent::EventTime)||time.is_a?(Integer))&&record.is_a?(Hash)feed_to_plugin(tag,OneEventStream.new(time,record))elseraiseArgumentError,"unexpected values of argument: #{tag.class}, #{time.class}, #{record.class}"endelseraiseArgumentError,"unexpected number of arguments: #{args}"endendendendendend