lib/mongoid/history/options.rb in mongoid-history-0.8.0 vs lib/mongoid/history/options.rb in mongoid-history-0.8.1

- old
+ new

@@ -55,14 +55,14 @@ next if field.nil? field = trackable.database_field_name(field) if format.class == Hash && trackable.embeds_many?(field) - relation_class = trackable.embeds_many_class(field) + relation_class = trackable.relation_class_of(field) formats[field] = format.inject({}) { |a, e| a.merge(relation_class.database_field_name(e.first) => e.last) } elsif format.class == Hash && trackable.embeds_one?(field) - relation_class = trackable.embeds_one_class(field) + relation_class = trackable.relation_class_of(field) formats[field] = format.inject({}) { |a, e| a.merge(relation_class.database_field_name(e.first) => e.last) } else formats[field] = format end end @@ -141,35 +141,26 @@ return if reserved_fields.include?(field) field_options = Array(field_options) if trackable.embeds_one?(field) - track_embeds_one(field, field_options) + track_relation(field, :embeds_one, field_options) elsif trackable.embeds_many?(field) - track_embeds_many(field, field_options) + track_relation(field, :embeds_many, field_options) elsif trackable.fields.keys.include?(field) @options[:fields] << field else @options[:dynamic] << field end end - def track_embeds_one(field, field_options) - relation_class = trackable.embeds_one_class(field) - @options[:relations][:embeds_one][field] = if field_options.blank? - relation_class.fields.keys - else - %w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) } - end - end - - def track_embeds_many(field, field_options) - relation_class = trackable.embeds_many_class(field) - @options[:relations][:embeds_many][field] = if field_options.blank? - relation_class.fields.keys - else - %w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) } - end + def track_relation(field, kind, field_options) + relation_class = trackable.relation_class_of(field) + @options[:relations][kind][field] = if field_options.blank? + relation_class.fields.keys + else + %w[_id] | field_options.map { |opt| relation_class.database_field_name(opt) } + end end def reserved_fields @reserved_fields ||= ['_id', '_type', options[:version_field].to_s, "#{options[:modifier_field]}_id"] end