Module: CustomFields::Types::Default::Field

Defined in:
lib/custom_fields/types/default.rb

Instance Method Summary collapse

Instance Method Details

#collect_default_diff(memo) ⇒ Hash

Build the mongodb updates based on the new state of the field

Parameters:

  • memo (Hash)

    Store the updates

Returns:

  • (Hash)

    The memo object upgraded



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/custom_fields/types/default.rb', line 14

def collect_default_diff(memo)
  # puts "collect_default_diff #{self.name}: #{self.persisted?} / #{self.destroyed?}" # DEBUG
  if persisted?
    if destroyed?
      memo['$unset'][name] = 1
    elsif changed?
      if changes.key?('name')
        old_name, new_name = changes['name']
        memo['$rename'][old_name] = new_name
      end
    end
  end

  (memo['$set']['custom_fields_recipe.rules'] ||= []) << to_recipe

  memo
end