Class: RulesIO::Rack

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

Direct Known Subclasses

Users

Constant Summary collapse

@@config_options =

cattr_accessor :config_options

{}

Instance Attribute Summary collapse

Attributes inherited from Base

#buffer, #token

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Rack

Returns a new instance of Rack.



20
21
22
23
24
25
26
27
28
# File 'lib/rulesio/rack.rb', line 20

def initialize(app, options={})
  self.class.config_options = @config_options = (options || {})
  RulesIO.instance = self
  @app = app
  @buffer = []
  @filter_parameters ||= defined?(Rails) ? Rails.application.config.filter_parameters : []
  @token = options[:token]
  @controller_data = options[:controller_data] || '{}'
end

Instance Attribute Details

#config_optionsObject

Returns the value of attribute config_options.



3
4
5
# File 'lib/rulesio/rack.rb', line 3

def config_options
  @config_options
end

#controller_dataObject

Returns the value of attribute controller_data.



3
4
5
# File 'lib/rulesio/rack.rb', line 3

def controller_data
  @controller_data
end

#filter_parametersObject

Returns the value of attribute filter_parameters.



3
4
5
# File 'lib/rulesio/rack.rb', line 3

def filter_parameters
  @filter_parameters
end

Class Method Details

.config_optionsObject



8
9
10
# File 'lib/rulesio/rack.rb', line 8

def self.config_options
  @@config_options
end

.config_options=(opts) ⇒ Object



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

def self.config_options=(opts)
  @@config_options = opts
end

Instance Method Details

#call(env) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rulesio/rack.rb', line 30

def call(env)
  @buffer = []
  request = ::Rack::Request.new(env)
  env['rulesio.request_url'] = request.url
  env['rulesio.request_method'] = request.request_method
  @app.call(env)
ensure
  flush(env)
end

#default_ignored_crawlersObject



16
17
18
# File 'lib/rulesio/rack.rb', line 16

def default_ignored_crawlers
  %w(Baidu Gigabot Googlebot libwww-perl lwp-trivial msnbot SiteUptime Slurp WordPress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot NewRelicPinger CopperEgg Pingdom UptimeRobot)
end

#flush(env = {}) ⇒ Object



44
45
46
47
48
# File 'lib/rulesio/rack.rb', line 44

def flush(env={})
  return if (events = @buffer).empty?
  @buffer = []
  RulesIO.queue.push(:token => @token, :payload => events.map {|event| prepare_event(event, env)})
end

#send_event(event) ⇒ Object



40
41
42
# File 'lib/rulesio/rack.rb', line 40

def send_event(event)
  @buffer << event
end