Skip to content

Commit e9ca055

Browse files
author
Robert Ross
committed
Add documentation to formatters spec.
1 parent fceab93 commit e9ca055

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lib/grape/entity.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)