Class: RulesIO::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rulesio/base.rb

Direct Known Subclasses

Rack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/rulesio/base.rb', line 6

def initialize(token)
  RulesIO.instance = self
  @token = token
  @buffer = []
end

Instance Attribute Details

#bufferObject

include Singleton



4
5
6
# File 'lib/rulesio/base.rb', line 4

def buffer
  @buffer
end

#tokenObject

include Singleton



4
5
6
# File 'lib/rulesio/base.rb', line 4

def token
  @token
end

Instance Method Details

#flushObject



16
17
18
19
20
# File 'lib/rulesio/base.rb', line 16

def flush
  return if (events = @buffer).empty?
  @buffer = []
  RulesIO.queue.push(:payload => events, :token => @token)
end

#send_event(event) ⇒ Object



12
13
14
# File 'lib/rulesio/base.rb', line 12

def send_event(event)
  @buffer << prepare_event(event)
end