Module: Blamescope
- Defined in:
- lib/blamescope.rb,
lib/blamescope/server.rb,
lib/blamescope/version.rb,
lib/blamescope/trackable.rb,
lib/blamescope/middleware.rb
Overview
Trackable module
Defined Under Namespace
Modules: Trackable Classes: Middleware, Server
Constant Summary collapse
- VERSION =
"0.0.4"
Class Attribute Summary collapse
-
.exchange ⇒ Object
Returns the value of attribute exchange.
Class Method Summary collapse
-
.configure(config) ⇒ Object
Configure Blamescope.
-
.emit(attrs) ⇒ Object
Send event.
- .included(base) ⇒ Object
-
.rabbit_connection(config) ⇒ Hash
Create RabbitMQ connection.
-
.user ⇒ String
Get current user.
Class Attribute Details
.exchange ⇒ Object
Returns the value of attribute exchange.
14 15 16 |
# File 'lib/blamescope.rb', line 14 def exchange @exchange end |
Class Method Details
.configure(config) ⇒ Object
Configure Blamescope
26 27 28 |
# File 'lib/blamescope.rb', line 26 def configure(config) self.exchange = rabbit_connection(config[:rabbit])[:exchange] end |
.emit(attrs) ⇒ Object
Send event
50 51 52 53 54 55 |
# 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) ⇒ Object
16 17 18 19 |
# File 'lib/blamescope.rb', line 16 def included(base) base.extend(Trackable) base.class.extend(Trackable) end |
.rabbit_connection(config) ⇒ Hash
Create RabbitMQ connection
62 63 64 65 66 67 68 |
# 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 ⇒ String
Get current user
34 35 36 37 38 39 40 41 |
# 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 |