Class: PostRevisor::TopicChanges
- Inherits:
-
Object
- Object
- PostRevisor::TopicChanges
- 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
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #check_result(res) ⇒ Object
- #diff ⇒ Object
- #errored? ⇒ Boolean
- #guardian ⇒ Object
-
#initialize(topic, user) ⇒ TopicChanges
constructor
A new instance of TopicChanges.
- #record_change(field_name, previous_val, new_val) ⇒ Object
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
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
12 13 14 |
# File 'lib/post_revisor.rb', line 12 def topic @topic end |
#user ⇒ Object (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 |
#diff ⇒ Object
38 39 40 |
# File 'lib/post_revisor.rb', line 38 def diff @diff ||= {} end |
#errored? ⇒ Boolean
21 22 23 |
# File 'lib/post_revisor.rb', line 21 def errored? @errored end |
#guardian ⇒ Object
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 |