Class: Rackful::Serializer Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rackful/serializer.rb

Overview

This class is abstract.

Subclasses must implement method #each end define constant CONTENT_TYPES

Base class for all serializers.

The serializers XHTML and JSON defined in this library depend on the presence of method resource.to_rackful.

Direct Known Subclasses

JSON, XHTML

Defined Under Namespace

Classes: JSON, XHTML

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Serializer) initialize(request, resource, content_type)

Returns a new instance of Serializer

Parameters:



34
35
36
37
# File 'lib/rackful/serializer.rb', line 34

def initialize request, resource, content_type
  @request, @resource, @content_type =
    request, resource, content_type
end

Instance Attribute Details

- (String) content_type (readonly)

Returns The content type to be served by this Serializer. This will always be one of the content types listed in constant CONTENT_TYPES.

Returns:

  • (String)

    The content type to be served by this Serializer. This will always be one of the content types listed in constant CONTENT_TYPES.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rackful/serializer.rb', line 22

class Serializer


  include Enumerable


  attr_reader :request, :resource, :content_type


  # @param request [Request]
  # @param resource [Resource]
  # @param content_type [String]
  def initialize request, resource, content_type
    @request, @resource, @content_type =
      request, resource, content_type
  end


  # @!method headers()
  #   Extra response headers that a serializer likes to return.
  #
  #   You don't have to include the `Content-Type` header, as this is done
  #   _for_ you.
  #
  #   This method is optional.
  #   @return [Hash]
  #   @abstract


  # @abstract Every serializer must implement this method.
  # @yieldparam block [String] (part of) the entity body
  def each
    raise NotImplementedError
  end


end

- (Request) request (readonly)

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rackful/serializer.rb', line 22

class Serializer


  include Enumerable


  attr_reader :request, :resource, :content_type


  # @param request [Request]
  # @param resource [Resource]
  # @param content_type [String]
  def initialize request, resource, content_type
    @request, @resource, @content_type =
      request, resource, content_type
  end


  # @!method headers()
  #   Extra response headers that a serializer likes to return.
  #
  #   You don't have to include the `Content-Type` header, as this is done
  #   _for_ you.
  #
  #   This method is optional.
  #   @return [Hash]
  #   @abstract


  # @abstract Every serializer must implement this method.
  # @yieldparam block [String] (part of) the entity body
  def each
    raise NotImplementedError
  end


end

- (Resource) resource (readonly)

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rackful/serializer.rb', line 22

class Serializer


  include Enumerable


  attr_reader :request, :resource, :content_type


  # @param request [Request]
  # @param resource [Resource]
  # @param content_type [String]
  def initialize request, resource, content_type
    @request, @resource, @content_type =
      request, resource, content_type
  end


  # @!method headers()
  #   Extra response headers that a serializer likes to return.
  #
  #   You don't have to include the `Content-Type` header, as this is done
  #   _for_ you.
  #
  #   This method is optional.
  #   @return [Hash]
  #   @abstract


  # @abstract Every serializer must implement this method.
  # @yieldparam block [String] (part of) the entity body
  def each
    raise NotImplementedError
  end


end

Instance Method Details

- (void) each {|block| ... }

This method is abstract.

Every serializer must implement this method.

Yield Parameters:

  • block (String)

    (part of) the entity body

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/rackful/serializer.rb', line 53

def each
  raise NotImplementedError
end

- (Hash) headers

This method is abstract.

Extra response headers that a serializer likes to return.

You don't have to include the Content-Type header, as this is done for you.

This method is optional.

Returns:

  • (Hash)


# File 'lib/rackful/serializer.rb', line 40