Class: Bullet::Notification::Base
- Inherits:
-
Object
- Object
- Bullet::Notification::Base
show all
- Defined in:
- lib/bullet/notification/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(base_class, association_or_associations, path = nil) ⇒ Base
Returns a new instance of Base.
9
10
11
12
13
14
|
# 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
|
Instance Attribute Details
#associations ⇒ Object
Returns the value of attribute associations.
7
8
9
|
# File 'lib/bullet/notification/base.rb', line 7
def associations
@associations
end
|
#base_class ⇒ Object
Returns the value of attribute base_class.
7
8
9
|
# File 'lib/bullet/notification/base.rb', line 7
def base_class
@base_class
end
|
#notifier ⇒ Object
Returns the value of attribute notifier.
6
7
8
|
# File 'lib/bullet/notification/base.rb', line 6
def notifier
@notifier
end
|
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'lib/bullet/notification/base.rb', line 7
def path
@path
end
|
#url ⇒ Object
Returns the value of attribute url.
6
7
8
|
# File 'lib/bullet/notification/base.rb', line 6
def url
@url
end
|
Instance Method Details
#body ⇒ Object
20
21
22
|
# File 'lib/bullet/notification/base.rb', line 20
def body
raise NoMethodError, 'no method body defined'
end
|
#body_with_caller ⇒ Object
41
42
43
|
# File 'lib/bullet/notification/base.rb', line 41
def body_with_caller
"#{body}\n#{call_stack_messages}\n"
end
|
#call_stack_messages ⇒ Object
24
25
26
|
# File 'lib/bullet/notification/base.rb', line 24
def call_stack_messages
''
end
|
#eql?(other) ⇒ Boolean
72
73
74
|
# File 'lib/bullet/notification/base.rb', line 72
def eql?(other)
self.class == other.class && klazz_associations_str == other.klazz_associations_str
end
|
#hash ⇒ Object
76
77
78
|
# File 'lib/bullet/notification/base.rb', line 76
def hash
[self.class, klazz_associations_str].hash
end
|
#notification_data ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/bullet/notification/base.rb', line 63
def notification_data
hash = {}
hash[:user] = whoami unless Bullet.skip_user_in_notification
hash[:url] = url
hash[:title] = title
hash[:body] = body_with_caller
hash
end
|
#notify_inline ⇒ Object
45
46
47
|
# File 'lib/bullet/notification/base.rb', line 45
def notify_inline
notifier.inline_notify(notification_data)
end
|
#notify_out_of_channel ⇒ Object
49
50
51
|
# File 'lib/bullet/notification/base.rb', line 49
def notify_out_of_channel
notifier.out_of_channel_notify(notification_data)
end
|
#short_notice ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/bullet/notification/base.rb', line 53
def short_notice
parts = []
parts << whoami.presence unless Bullet.skip_user_in_notification
parts << url
parts << title
parts << body
parts.compact.join(' ')
end
|
#title ⇒ Object
16
17
18
|
# File 'lib/bullet/notification/base.rb', line 16
def title
raise NoMethodError, 'no method title defined'
end
|
#whoami ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/bullet/notification/base.rb', line 28
def whoami
@user ||=
ENV['USER'].presence ||
(
begin
`whoami`.chomp
rescue StandardError
''
end
)
@user.present? ? "user: #{@user}" : ''
end
|