File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,32 @@ def self.exposures
9595
9696 # This allows you to declare a Proc in which exposures can be formatted with.
9797 # It take a block with an arity of 1 which is passed as the value of the exposed attribute.
98+ #
99+ # @param name [Symbol] the name of the formatter
100+ # @param block [Proc] the block that will interpret the exposed attribute
101+ #
102+ #
103+ #
104+ # @example Formatter declaration
105+ #
106+ # module API
107+ # module Entities
108+ # class User < Grape::Entity
109+ # format_with :timestamp do |date|
110+ # date.strftime('%m/%d/%Y')
111+ # end
112+ #
113+ # expose :birthday, :last_signed_in, :format_with => :timestamp
114+ # end
115+ # end
116+ # end
117+ #
118+ # @example Formatters are available to all decendants
119+ #
120+ # Grape::Entity.format_with :timestamp do |date|
121+ # date.strftime('%m/%d/%Y')
122+ # end
123+ #
98124 def self . format_with ( name , &block )
99125 raise ArgumentError , "You must has a block for formatters" unless block_given?
100126 formatters [ name . to_sym ] = block
You can’t perform that action at this time.
0 commit comments