Module: Mongoid::History::Trackable::ClassMethods
- Defined in:
- lib/mongoid/history/trackable.rb
Instance Method Summary collapse
- #disable_tracking(&_block) ⇒ Object
- #dynamic_enabled? ⇒ Boolean
- #history_settings(options = {}) ⇒ Object
- #track_history(options = {}) ⇒ Object
- #track_history? ⇒ Boolean
- #track_history_flag ⇒ Object
- #tracker_class ⇒ Object
Instance Method Details
#disable_tracking(&_block) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/mongoid/history/trackable.rb', line 55 def disable_tracking(&_block) Mongoid::History.store[track_history_flag] = false yield ensure Mongoid::History.store[track_history_flag] = true end |
#dynamic_enabled? ⇒ Boolean
51 52 53 |
# File 'lib/mongoid/history/trackable.rb', line 51 def dynamic_enabled? Mongoid::Compatibility::Version.mongoid3? || (self < Mongoid::Attributes::Dynamic).present? end |
#history_settings(options = {}) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mongoid/history/trackable.rb', line 39 def history_settings( = {}) = Mongoid::History.default_settings.merge(.symbolize_keys) = .slice(*Mongoid::History.default_settings.keys) [:paranoia_field] = aliased_fields[[:paranoia_field].to_s] || [:paranoia_field].to_s Mongoid::History.trackable_settings ||= {} Mongoid::History.trackable_settings[name.to_sym] = end |
#track_history(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mongoid/history/trackable.rb', line 7 def track_history( = {}) extend RelationMethods = Mongoid::History::Options.new(self, ) field .[:version_field].to_sym, type: Integer unless .[:modifier_field].nil? = { class_name: Mongoid::History.modifier_class_name } [:inverse_of] = .[:modifier_field_inverse_of] if ..key?(:modifier_field_inverse_of) [:optional] = true if .[:modifier_field_optional] && Mongoid::Compatibility::Version.mongoid6_or_newer? belongs_to .[:modifier_field].to_sym, end include MyInstanceMethods extend SingletonMethods delegate :history_trackable_options, to: 'self.class' delegate :track_history?, to: 'self.class' = ..slice(:if, :unless) around_update :track_update, if .[:track_update] around_create :track_create, if .[:track_create] around_destroy :track_destroy, if .[:track_destroy] unless respond_to? :mongoid_history_options class_attribute :mongoid_history_options, instance_accessor: false end self. = end |
#track_history? ⇒ Boolean
47 48 49 |
# File 'lib/mongoid/history/trackable.rb', line 47 def track_history? Mongoid::History.enabled? && Mongoid::History.store[track_history_flag] != false end |
#track_history_flag ⇒ Object
62 63 64 |
# File 'lib/mongoid/history/trackable.rb', line 62 def track_history_flag "mongoid_history_#{name.underscore}_trackable_enabled".to_sym end |
#tracker_class ⇒ Object
66 67 68 69 |
# File 'lib/mongoid/history/trackable.rb', line 66 def tracker_class klass = [:tracker_class_name] || Mongoid::History.tracker_class_name klass.is_a?(Class) ? klass : klass.to_s.camelize.constantize end |