Module: Noticed::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/noticed/model.rb

Constant Summary collapse

DATABASE_ERROR_CLASS_NAMES =
lambda {
  classes = [ActiveRecord::NoDatabaseError]
  classes << ActiveRecord::ConnectionNotEstablished
  classes << Mysql2::Error if defined?(::Mysql2)
  classes << PG::ConnectionBad if defined?(::PG)
  classes
}.call.freeze

Instance Method Summary collapse

Instance Method Details

#deserialize_error?Boolean

If a GlobalID record in params is no longer found, the params will default with a noticed_error key

Returns:

  • (Boolean)


81
82
83
# File 'lib/noticed/model.rb', line 81

def deserialize_error?
  !!params[:noticed_error]
end

#mark_as_read!Object



64
65
66
# File 'lib/noticed/model.rb', line 64

def mark_as_read!
  update(read_at: Time.current)
end

#mark_as_unread!Object



68
69
70
# File 'lib/noticed/model.rb', line 68

def mark_as_unread!
  update(read_at: nil)
end

#read?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/noticed/model.rb', line 76

def read?
  read_at?
end

#to_notificationObject

Rehydrate the database notification into the Notification object for rendering



55
56
57
58
59
60
61
62
# File 'lib/noticed/model.rb', line 55

def to_notification
  @_notification ||= begin
    instance = type.constantize.with(params)
    instance.record = self
    instance.recipient = recipient
    instance
  end
end

#unread?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/noticed/model.rb', line 72

def unread?
  !read?
end