Module: Notably::Notification::ClassMethods

Defined in:
lib/notably/notification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



123
124
125
# File 'lib/notably/notification.rb', line 123

def callbacks
  @callbacks
end

Class Method Details

.extended(base) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/notably/notification.rb', line 125

def self.extended(base)
  base.class_eval do
    @callbacks = {after_notify: [], before_notify: []}
    @group_by = []
    @group_within = ->(receiver) { receiver.last_notification_read_at }
    @required_attributes = []
  end
end

Instance Method Details

#after_notify(method = nil, &block) ⇒ Object



170
171
172
# File 'lib/notably/notification.rb', line 170

def after_notify(method=nil, &block)
  @callbacks[:after_notify] << (block || method)
end

#before_notify(method = nil, &block) ⇒ Object



166
167
168
# File 'lib/notably/notification.rb', line 166

def before_notify(method=nil, &block)
  @callbacks[:before_notify] << (block || method)
end

#create(attributes = {}) ⇒ Object



134
135
136
# File 'lib/notably/notification.rb', line 134

def create(attributes={})
  new(attributes).save
end

#group?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/notably/notification.rb', line 154

def group?
  @group_by.any?
end

#group_by(*args) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/notably/notification.rb', line 146

def group_by(*args)
  if args.any?
    @group_by += args
  else
    @group_by
  end
end

#group_within(block = nil) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/notably/notification.rb', line 158

def group_within(block=nil)
  if block
    @group_within = block
  else
    @group_within
  end
end

#required_attributes(*args) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/notably/notification.rb', line 138

def required_attributes(*args)
  if args.any?
    @required_attributes += args
  else
    @required_attributes
  end
end