Skip to content

Commit

Permalink
Removes optional using first comments records
Browse files Browse the repository at this point in the history
Removes optional using of note's first comments records for retrieving note's description, author_id, author_ip in Note model file.
  • Loading branch information
nenad-vujicic committed Jan 20, 2025
1 parent 3e61932 commit 2618a49
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,19 @@ def freshly_closed_until
closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT
end

# Return the note's description, unless record is unavailable and
# it will be derived from the first comment
# Return the note's description
def description
if user_ip.nil? && user_id.nil?
comments.first.body
else
RichText.new("text", self[:description])
end
RichText.new("text", self[:description])
end

# Return the note's author object, unless record is unavailable and
# it will be derived from the first comment
def author
if user_ip.nil? && user_id.nil?
comments.first.author
else
self[:author]
end
end

# Return the note's author ID, unless record is unavailable and
# it will be derived from the first comment
# Return the note's author ID
def author_id
if user_ip.nil? && user_id.nil?
comments.first.author_id
else
user_id
end
user_id
end

# Return the note's author IP address, unless record is unavailable and
# it will be derived from the first comment
# Return the note's author IP address
def author_ip
if user_ip.nil? && user_id.nil?
comments.first.author_ip
else
user_ip
end
user_ip
end

private
Expand Down

0 comments on commit 2618a49

Please sign in to comment.