0
我是葡萄::實體工作了定製響應 但是,當我看到 Grape::Entity葡萄::實體定製響應解釋
文檔它說,與虎視眈眈::實體,我們可以在運行時決定哪個屬性發送&哪些不是。 但我無法理解的代碼甚至給出提示
expose :ip, if: { type: :full }
expose :ip, if: lambda { |instance, options| options[:type] == :full } # exposed if the function evaluates to true
expose :ip, if: :type # exposed if :type is available in the options hash
expose :ip, if: { type: :full } # exposed if options :type has a value of :full
expose :ip, unless: ... # the opposite of :if
expose :last_reply, using: API::Entities::Status do |status, options|
status.replies.last
end
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
expose :digest do |status, options|
Digest::MD5.hexdigest status.txt
end
我會很感激,如果有人通過行解釋線