Module: Mongoid::History::Trackable::SingletonMethods
- Defined in:
- lib/mongoid/history/trackable.rb
Instance Method Summary collapse
-
#embedded_alias(embed) ⇒ String
Retrieves the database representation of an embedded field name, in case the :store_as option is used.
-
#embeds_many?(embed) ⇒ Boolean
Indicates whether there is an Embedded::Many relation for the given embedded field.
-
#embeds_one?(embed) ⇒ Boolean
Indicates whether there is an Embedded::One relation for the given embedded field.
- #history_trackable_options ⇒ Object
-
#reserved_tracked_fields ⇒ Array < String >
Retrieves the memoized list of reserved tracked fields, which are only included for certain actions.
-
#tracked_field?(field, action = :update) ⇒ Boolean
Whether or not the field should be tracked.
-
#tracked_fields ⇒ Array < String >
Retrieves the memoized base list of tracked fields, excluding reserved fields.
-
#tracked_fields_for_action(action) ⇒ Array < String >
Retrieves the list of tracked fields for a given action.
Instance Method Details
#embedded_alias(embed) ⇒ String
Retrieves the database representation of an embedded field name, in case the :store_as option is used.
330 331 332 |
# File 'lib/mongoid/history/trackable.rb', line 330 def () [] end |
#embeds_many?(embed) ⇒ Boolean
Indicates whether there is an Embedded::Many relation for the given embedded field.
321 322 323 |
# File 'lib/mongoid/history/trackable.rb', line 321 def () relation_of() == Mongoid::Relations::Embedded::Many end |
#embeds_one?(embed) ⇒ Boolean
Indicates whether there is an Embedded::One relation for the given embedded field.
312 313 314 |
# File 'lib/mongoid/history/trackable.rb', line 312 def () relation_of() == Mongoid::Relations::Embedded::One end |
#history_trackable_options ⇒ Object
303 304 305 |
# File 'lib/mongoid/history/trackable.rb', line 303 def @history_trackable_options ||= Mongoid::History.[collection_name.to_s.singularize.to_sym] end |
#reserved_tracked_fields ⇒ Array < String >
Retrieves the memoized list of reserved tracked fields, which are only included for certain actions.
299 300 301 |
# File 'lib/mongoid/history/trackable.rb', line 299 def reserved_tracked_fields @reserved_tracked_fields ||= ["_id", [:version_field].to_s, "#{[:modifier_field]}_id"] end |
#tracked_field?(field, action = :update) ⇒ Boolean
Whether or not the field should be tracked.
270 271 272 |
# File 'lib/mongoid/history/trackable.rb', line 270 def tracked_field?(field, action = :update) tracked_fields_for_action(action).include? database_field_name(field) end |
#tracked_fields ⇒ Array < String >
Retrieves the memoized base list of tracked fields, excluding reserved fields.
289 290 291 292 293 294 |
# File 'lib/mongoid/history/trackable.rb', line 289 def tracked_fields @tracked_fields ||= fields.keys.select do |field| h = (h[:on] == :all || h[:on].include?(field)) && !h[:except].include?(field) end - reserved_tracked_fields end |
#tracked_fields_for_action(action) ⇒ Array < String >
Retrieves the list of tracked fields for a given action.
279 280 281 282 283 284 |
# File 'lib/mongoid/history/trackable.rb', line 279 def tracked_fields_for_action(action) case action.to_sym when :destroy then tracked_fields + reserved_tracked_fields else tracked_fields end end |