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:
@@ -72,6 +72,8 @@ class Upload < ApplicationRecord
|
||||
|
||||
scope :preprocessed, -> { where(status: "preprocessed") }
|
||||
|
||||
api_attributes including: [:uploader_name]
|
||||
|
||||
def initialize_attributes
|
||||
self.uploader_id = CurrentUser.id
|
||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||
@@ -227,18 +229,11 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def method_attributes
|
||||
super + [:uploader_name]
|
||||
end
|
||||
end
|
||||
|
||||
include FileMethods
|
||||
include StatusMethods
|
||||
include UploaderMethods
|
||||
include VideoMethods
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
include SourceMethods
|
||||
|
||||
def uploader_is_not_limited
|
||||
|
||||
Reference in New Issue
Block a user