api: refactor api attribute declarations.
Replace the `method_attributes` and `hidden_attributes` methods with
`api_attributes`. `api_attributes` can be used as a class macro:
# include only the given attributes.
api_attributes :id, :created_at, :creator_name, ...
# include all default attributes plus the `creator_name` method.
api_attributes including: [:creator_name]
or as an instance method:
def api_attributes
[:id, :created_at, :creator_name, ...]
end
By default, all attributes are included except for IP addresses and
tsvector columns.
This commit is contained in:
@@ -22,6 +22,8 @@ class Comment < ApplicationRecord
|
||||
:body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n"},
|
||||
)
|
||||
|
||||
api_attributes including: [:creator_name, :updater_name]
|
||||
|
||||
module SearchMethods
|
||||
def deleted
|
||||
where("comments.is_deleted = true")
|
||||
@@ -145,14 +147,6 @@ class Comment < ApplicationRecord
|
||||
select { |comment| comment.visibility(user) == :visible }
|
||||
end
|
||||
|
||||
def hidden_attributes
|
||||
super + [:body_index]
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:creator_name, :updater_name]
|
||||
end
|
||||
|
||||
def creator_name
|
||||
creator.name
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user