Class: ModelTimeline::TimelineEntry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ModelTimeline::TimelineEntry
- Defined in:
- lib/model_timeline/timeline_entry.rb
Overview
Represents a timeline entry that records changes to a model. TimelineEntry stores the tracked object, user who made the change, IP address, and the changes that were made.
Instance Attribute Summary collapse
-
#timelineable ⇒ Object
The model instance that this timeline entry belongs to.
-
#user ⇒ Object
The user who made the change.
Class Method Summary collapse
-
.for_ip_address(ip) ⇒ ActiveRecord::Relation
Retrieves timeline entries from a specific IP address.
-
.for_timelineable(timelineable) ⇒ ActiveRecord::Relation
Retrieves timeline entries for a specific timelineable object.
-
.for_user(user) ⇒ ActiveRecord::Relation
Retrieves timeline entries created by a specific user.
-
.with_changed_attribute(attribute) ⇒ ActiveRecord::Relation
Retrieves timeline entries where a specific attribute was changed.
-
.with_changed_value(attribute, value) ⇒ ActiveRecord::Relation
Retrieves timeline entries where an attribute was changed to a specific value.
Instance Attribute Details
#timelineable ⇒ Object
Returns The model instance that this timeline entry belongs to.
13 |
# File 'lib/model_timeline/timeline_entry.rb', line 13 belongs_to :timelineable, polymorphic: true, optional: true |
#user ⇒ Object
Returns The user who made the change.
17 |
# File 'lib/model_timeline/timeline_entry.rb', line 17 belongs_to :user, polymorphic: true, optional: true |
Class Method Details
.for_ip_address(ip) ⇒ ActiveRecord::Relation
Retrieves timeline entries from a specific IP address
39 40 41 |
# File 'lib/model_timeline/timeline_entry.rb', line 39 def self.for_ip_address(ip) where(ip_address: ip) end |
.for_timelineable(timelineable) ⇒ ActiveRecord::Relation
Retrieves timeline entries for a specific timelineable object
23 24 25 |
# File 'lib/model_timeline/timeline_entry.rb', line 23 def self.for_timelineable(timelineable) where(timelineable_type: timelineable.class.name, timelineable_id: timelineable.id) end |
.for_user(user) ⇒ ActiveRecord::Relation
Retrieves timeline entries created by a specific user
31 32 33 |
# File 'lib/model_timeline/timeline_entry.rb', line 31 def self.for_user(user) where(user_type: user.class.name, user_id: user.id) end |
.with_changed_attribute(attribute) ⇒ ActiveRecord::Relation
Retrieves timeline entries where a specific attribute was changed
47 48 49 |
# File 'lib/model_timeline/timeline_entry.rb', line 47 def self.with_changed_attribute(attribute) where('object_changes ? :key', key: attribute.to_s) end |
.with_changed_value(attribute, value) ⇒ ActiveRecord::Relation
Retrieves timeline entries where an attribute was changed to a specific value
56 57 58 |
# File 'lib/model_timeline/timeline_entry.rb', line 56 def self.with_changed_value(attribute, value) where('object_changes -> :key ->> 1 = :value', key: attribute.to_s, value: value.to_s) end |