Class: PostRevisor::TopicChanges

Inherits:
Object
  • Object
show all
Defined in:
lib/post_revisor.rb

Overview

Helps us track changes to a topic.

It’s passed to ‘track_topic_fields` callbacks so they can record if they changed a value or not. This is needed for things like custom fields.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic, user) ⇒ TopicChanges

Returns a new instance of TopicChanges.



14
15
16
17
18
19
# File 'lib/post_revisor.rb', line 14

def initialize(topic, user)
  @topic = topic
  @user = user
  @changed = {}
  @errored = false
end

Instance Attribute Details

#topicObject (readonly)

Returns the value of attribute topic.



12
13
14
# File 'lib/post_revisor.rb', line 12

def topic
  @topic
end

#userObject (readonly)

Returns the value of attribute user.



12
13
14
# File 'lib/post_revisor.rb', line 12

def user
  @user
end

Instance Method Details

#check_result(res) ⇒ Object



34
35
36
# File 'lib/post_revisor.rb', line 34

def check_result(res)
  @errored = true if !res
end

#diffObject



38
39
40
# File 'lib/post_revisor.rb', line 38

def diff
  @diff ||= {}
end

#errored?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/post_revisor.rb', line 21

def errored?
  @errored
end

#guardianObject



25
26
27
# File 'lib/post_revisor.rb', line 25

def guardian
  @guardian ||= Guardian.new(@user)
end

#record_change(field_name, previous_val, new_val) ⇒ Object



29
30
31
32
# File 'lib/post_revisor.rb', line 29

def record_change(field_name, previous_val, new_val)
  return if previous_val == new_val
  diff[field_name] = [previous_val, new_val]
end