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:
@@ -17,6 +17,8 @@ class Pool < ApplicationRecord
|
||||
after_save :create_version
|
||||
after_create :synchronize!
|
||||
|
||||
api_attributes including: [:creator_name, :post_count]
|
||||
|
||||
module SearchMethods
|
||||
def deleted
|
||||
where("pools.is_deleted = true")
|
||||
@@ -288,10 +290,6 @@ class Pool < ApplicationRecord
|
||||
(post_count / CurrentUser.user.per_page.to_f).ceil
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:creator_name, :post_count]
|
||||
end
|
||||
|
||||
def creator_name
|
||||
creator.name
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user