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:
@@ -94,22 +94,13 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def hidden_attributes
|
||||
list = super
|
||||
unless CurrentUser.can_view_flagger_on_post?(self)
|
||||
list += [:creator_id]
|
||||
end
|
||||
super + list
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:category]
|
||||
end
|
||||
def api_attributes
|
||||
attributes = super + [:category]
|
||||
attributes -= [:creator_id] unless CurrentUser.can_view_flagger_on_post?(self)
|
||||
attributes
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def category
|
||||
case reason
|
||||
|
||||
Reference in New Issue
Block a user