Skip to content

Commit

Permalink
Add sort order method that doesn't reload the class.
Browse files Browse the repository at this point in the history
  • Loading branch information
avinashbot committed Oct 4, 2017
1 parent 13e3d33 commit b5d07f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/redd/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def initialize(endpoint:, user_agent: USER_AGENT)
# @option options [Hash] :body the direct body contents
# @return [Response] the response
def request(verb, path, options = {})
# puts "#{verb.to_s.upcase} #{path}", ' ' + options.inspect
response = connection.request(verb, path, **options)
Response.new(response.status.code, response.headers, response.body.to_s)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/redd/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class Comment < Model
# @deprecated is always 0; use {#score} instead
property :downs

# @!attribute [r] parent_id
# @return [String] the parent fullname
property :parent_id

# @!attribute [r] parent
# @return [Comment, Submission] the comment parent
property :parent,
Expand Down
8 changes: 7 additions & 1 deletion lib/redd/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Submission < Model
include Replyable
include Reportable

# @return [String] the sort order
def sort_order
exists_locally?(:sort_order) ? read_attribute(:sort_order) : nil
end

# Set the sort order of the comments and reload the comments.
# @param new_order [:confidence, :top, :controversial, :old, :qa] the sort order
def update_sort_order(new_order)
Expand Down Expand Up @@ -103,7 +108,8 @@ def set_suggested_sort(suggested) # rubocop:disable Naming/AccessorMethodName

# @!attribute [r] comments
# @return [Array<Comment>] the comment tree
property :comments, :nil, with: ->(l) { Listing.new(client, l) if l }
property :comments, :nil,
with: ->(l) { CommentListing.new(self, l ? Listing.new(client, l) : nil) }

# @!attribute [r] domain
# @return [String] the domain name of the link (or self.subreddit_name)
Expand Down

0 comments on commit b5d07f7

Please sign in to comment.