module Blamescope

Blamescope module

@author Volodymyr Ladnik

Trackable module

@author Volodymyr Ladnik

Constants

VERSION

Attributes

exchange[RW]

Public Class Methods

configure(config) click to toggle source

Configure Blamescope @param [Hash] config @option config [String] :rabbit Rabbit connection in format amqp://user:pass@host:port/vhost

# File lib/blamescope.rb, line 26
def configure(config)
  self.exchange = rabbit_connection(config[:rabbit])[:exchange]
end
emit(attrs) click to toggle source

Send event @param [type] attrs event attributes @option attrs [String] :model current class name @option attrs [String] :action current method @option attrs [String] :attrs object attributes

# File lib/blamescope.rb, line 50
def emit(attrs)
  attrs[:email] ||= user
  exchange.publish(attrs.to_json)
rescue Bunny::ConnectionClosedError
  puts "Bunny is down: couldn't send #{attrs[:action]} action for #{attrs[:model]} model"
end
included(base) click to toggle source
# File lib/blamescope.rb, line 16
def included(base)
  base.extend(Trackable)
  base.class.extend(Trackable)
end
rabbit_connection(config) click to toggle source

Create RabbitMQ connection @param config [String] Rabbit connection in format amqp://user:pass@host:port/vhost

@return [Hash] rabbit connection, channel and exchange

# File lib/blamescope.rb, line 62
def rabbit_connection(config)
  conn = Bunny.new(config)
  conn.start
  channel = conn.create_channel
  exchange = channel.fanout("blamescope")
  {conn: conn, channel: channel, exchange: exchange}
end
user() click to toggle source

Get current user

@return [String] user email

# File lib/blamescope.rb, line 34
def user
  env = Thread.current[:env]
  if env && env['warden']
    env['warden'].user.email
  else
     "#{ENV['USER']}@#{Socket.gethostname}"
  end
end