Class: Request::Base::EventCollection

Inherits:
Event
  • Object
show all
Includes:
Enumerable
Defined in:
lib/violet/request.rb

Overview

combine many Event in a single request

Instance Method Summary collapse

Methods inherited from Event

#+, #streamed?

Constructor Details

#initialize(one, another) ⇒ EventCollection

create a new EventCollection with two childrens.



59
60
61
62
63
64
65
# File 'lib/violet/request.rb', line 59

def initialize one, another
  if one.respond_to?(:to_url) and another.respond_to?(:to_url) # \_o<  Coin !
    @childrens = [ one, another ]
  else
    raise ArgumentError.new('bad parameters')
  end
end

Instance Method Details

#eachObject

needed by Enumerable module. usage should be obvious :)



69
70
71
72
73
74
75
76
77
# File 'lib/violet/request.rb', line 69

def each
  @childrens.each do |e|
    if e.kind_of? Enumerable
      e.each { |i| yield i }
    else
      yield e
    end
  end
end

#to_urlObject

override Event#to_url.



80
81
82
# File 'lib/violet/request.rb', line 80

def to_url
  @childrens.collect { |e| e.to_url }.flatten
end