Sha256: beb1a7d1d9be8c9409f5ae0ce23277583830c334c627766bfec6c8bfadaf0b43
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true require 'multi_json' class JSONWithIndifferentAccess def self.load(str) return str unless str obj = HashWithIndifferentAccess.new(MultiJson.load(str)) obj.freeze obj end def self.dump(obj) MultiJson.dump(obj) end end module Stance class EventRecord < ActiveRecord::Base belongs_to :subject, polymorphic: true scope :active, -> { where dismissed_at: nil } scope :dismissed, -> { where.not dismissed_at: nil } def self.table_name_prefix 'stance_' end def self.dismiss_all active.each(&:dismiss) end def to_s name end def event_class_name @event_class_name ||= "#{subject_type}Events::#{name.tr('.', '/').classify}" end def event_class @event_class ||= event_class_name.constantize end def dismissed? dismissed_at.present? end def active? !dismissed? end def dismiss update_attribute :dismissed_at, Time.current end unless connection.adapter_name =~ /postg|mysql/i serialize :metadata, coder: ::JSONWithIndifferentAccess end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stance-0.8.3 | app/models/stance/event_record.rb |
stance-0.8.2 | app/models/stance/event_record.rb |