class Bullet::Notification::Base

Attributes

associations[R]
base_class[R]
notifier[RW]
path[R]
url[RW]

Public Class Methods

new(base_class, association_or_associations, path = nil) click to toggle source
# File lib/bullet/notification/base.rb, line 9
def initialize(base_class, association_or_associations, path = nil)
  @base_class = base_class
  @associations = association_or_associations.is_a?(Array) ? association_or_associations : [association_or_associations]
  @path = path
end

Public Instance Methods

body() click to toggle source
# File lib/bullet/notification/base.rb, line 19
def body
  raise NoMethodError, 'no method body defined'
end
body_with_caller() click to toggle source
# File lib/bullet/notification/base.rb, line 40
def body_with_caller
  "#{body}\n#{call_stack_messages}\n"
end
call_stack_messages() click to toggle source
# File lib/bullet/notification/base.rb, line 23
def call_stack_messages
  ''
end
eql?(other) click to toggle source
# File lib/bullet/notification/base.rb, line 65
def eql?(other)
  self.class == other.class && klazz_associations_str == other.klazz_associations_str
end
hash() click to toggle source
# File lib/bullet/notification/base.rb, line 69
def hash
  [self.class, klazz_associations_str].hash
end
notification_data() click to toggle source
# File lib/bullet/notification/base.rb, line 56
def notification_data
  {
    user: whoami,
    url: url,
    title: title,
    body: body_with_caller
  }
end
notify_inline() click to toggle source
# File lib/bullet/notification/base.rb, line 44
def notify_inline
  notifier.inline_notify(notification_data)
end
notify_out_of_channel() click to toggle source
# File lib/bullet/notification/base.rb, line 48
def notify_out_of_channel
  notifier.out_of_channel_notify(notification_data)
end
short_notice() click to toggle source
# File lib/bullet/notification/base.rb, line 52
def short_notice
  [whoami.presence, url, title, body].compact.join('  ')
end
title() click to toggle source
# File lib/bullet/notification/base.rb, line 15
def title
  raise NoMethodError, 'no method title defined'
end
whoami() click to toggle source
# File lib/bullet/notification/base.rb, line 27
def whoami
  @user ||= ENV['USER'].presence || (begin
                                       `whoami`.chomp
                                     rescue StandardError
                                       ''
                                     end)
  if @user.present?
    "user: #{@user}"
  else
    ''
  end
end

Protected Instance Methods

associations_str() click to toggle source
# File lib/bullet/notification/base.rb, line 79
def associations_str
  ":includes => #{@associations.map { |a| a.to_s.to_sym unless a.is_a? Hash }.inspect}"
end
klazz_associations_str() click to toggle source
# File lib/bullet/notification/base.rb, line 75
def klazz_associations_str
  "  #{@base_class} => [#{@associations.map(&:inspect).join(', '.freeze)}]"
end