Module: Central::Support::ActivityConcern::Scopes

Extended by:
ActiveSupport::Concern
Defined in:
lib/central/support/concerns/activity_concern/scopes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#decorateObject



38
39
40
# File 'lib/central/support/concerns/activity_concern/scopes.rb', line 38

def decorate
  self
end

#merge_story!(activity) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/central/support/concerns/activity_concern/scopes.rb', line 17

def merge_story!(activity)
  return if subject_type != 'Story' # story only
  return if subject_id != activity.subject_id # only merge the exact same story change
  return if updated_at > activity.updated_at # only merge from future changes
  return if activity.subject_changes.blank?

  self.subject_changes = {} if self.subject_changes.nil?
  self.action = activity.action

  activity.subject_changes.keys.each do |key|
    if subject_changes[key]
      self.subject_changes[key][-1] = activity.subject_changes[key][-1]
    else
      self.subject_changes[key] = activity.subject_changes[key]
    end
    if self.subject_changes[key].first == self.subject_changes[key].last
      self.subject_changes.delete(key)
    end
  end
end