app/models/effective/log.rb in effective_logging-1.11.5 vs app/models/effective/log.rb in effective_logging-2.0.0
- old
+ new
@@ -9,19 +9,12 @@
# Self-Referencing relationship
belongs_to :parent, class_name: 'Effective::Log', counter_cache: true
has_many :logs, class_name: 'Effective::Log', foreign_key: :parent_id
- # The user this log item is referring to
- # An associated object, if we wanna add anything extra
- if Gem::Version.new(Rails.version) < Gem::Version.new('5.0')
- belongs_to :user
- belongs_to :associated, polymorphic: true
- else
- belongs_to :user, optional: true
- belongs_to :associated, polymorphic: true, optional: true
- end
+ belongs_to :user
+ belongs_to :associated, polymorphic: true
serialize :details, Hash
# Attributes
# logs_count :integer # Rails Counter Cache
@@ -35,12 +28,12 @@
# timestamps
validates :message, presence: true
validates :status, presence: true, inclusion: { in: EffectiveLogging.statuses }
- default_scope -> { order(updated_at: :desc) }
-
+ scope :deep, -> { includes(:user, :associated) }
+ scope :sorted, -> { order(:id) }
scope :logged_changes, -> { where(status: EffectiveLogging.log_changes_status)}
scope :changes, -> { where(status: EffectiveLogging.log_changes_status)}
def to_s
"Log #{id}"
@@ -55,17 +48,9 @@
end
def details
self[:details] || {}
end
-
- # def next_log
- # @next_log ||= Log.unscoped.order(:id).where(:parent_id => self.parent_id).where('id > ?', self.id).first
- # end
-
- # def prev_log
- # @prev_log ||= Log.unscoped.order(:id).where(:parent_id => self.parent_id).where('id < ?', self.id).last
- # end
# Dynamically add logging methods based on the defined statuses
# EffectiveLogging.info 'my message'
(EffectiveLogging.statuses || []).each do |status|
send(:define_method, status) { |message, options={}| log(message, status, options) }