Prevent exports crashing out if a related object is nil
This commit is contained in:
parent
f91246986c
commit
fe6a03bfaf
|
@ -156,6 +156,8 @@ class Exporter
|
||||||
if opts[:include_answers]
|
if opts[:include_answers]
|
||||||
qobj[:answers] = []
|
qobj[:answers] = []
|
||||||
question.answers.each do |a|
|
question.answers.each do |a|
|
||||||
|
next if a.nil?
|
||||||
|
|
||||||
qobj[:answers] << process_answer(a, include_question: false)
|
qobj[:answers] << process_answer(a, include_question: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -179,17 +181,19 @@ class Exporter
|
||||||
aobj[f] = answer.send f
|
aobj[f] = answer.send f
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:include_user]
|
if opts[:include_user] && answer.user
|
||||||
aobj[:user] = user_stub(answer.user)
|
aobj[:user] = user_stub(answer.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:include_question]
|
if opts[:include_question] && answer.question
|
||||||
aobj[:question] = process_question(answer.question, include_user: true, include_answers: false)
|
aobj[:question] = process_question(answer.question, include_user: true, include_answers: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:include_comments]
|
if opts[:include_comments]
|
||||||
aobj[:comments] = []
|
aobj[:comments] = []
|
||||||
answer.comments.each do |c|
|
answer.comments.each do |c|
|
||||||
|
next if c.nil?
|
||||||
|
|
||||||
aobj[:comments] << process_comment(c, include_user: true, include_answer: false)
|
aobj[:comments] << process_comment(c, include_user: true, include_answer: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -212,7 +216,7 @@ class Exporter
|
||||||
cobj[:user] = user_stub(comment.user)
|
cobj[:user] = user_stub(comment.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:include_answer]
|
if opts[:include_answer] && comment.answer
|
||||||
cobj[:answer] = process_answer(comment.answer, include_comments: false)
|
cobj[:answer] = process_answer(comment.answer, include_comments: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -220,6 +224,8 @@ class Exporter
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_smile(smile)
|
def process_smile(smile)
|
||||||
|
return unless smile.parent
|
||||||
|
|
||||||
sobj = {}
|
sobj = {}
|
||||||
|
|
||||||
%i[id created_at].each do |f|
|
%i[id created_at].each do |f|
|
||||||
|
@ -233,6 +239,7 @@ class Exporter
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_stub(user)
|
def user_stub(user)
|
||||||
|
return nil if user.nil?
|
||||||
uobj = {}
|
uobj = {}
|
||||||
%i[answered_count asked_count comment_smiled_count commented_count created_at
|
%i[answered_count asked_count comment_smiled_count commented_count created_at
|
||||||
id permanently_banned? screen_name smiled_count].each do |f|
|
id permanently_banned? screen_name smiled_count].each do |f|
|
||||||
|
|
Loading…
Reference in New Issue