Create a metadata method builder.

    Returns:

        A builder function that, given a class, creates a metadata
        relationship for that class.

def metadata():
    """Create a metadata method builder.

    Returns:

        A builder function that, given a class, creates a metadata
        relationship for that class.
    """
    def method_builder(cls):
        method_doc = """Fetch the metadata for this :class:`{0}`.

        Returns:

            The :class:`Metadata` for this :class:`{0}`
        """.format(cls.__name__)

        def method(self):
            session = self._session
            resource_id = None if self.is_singleton() else self.id
            resource_path = cls._resource_path()
            url = session._build_url(resource_path, resource_id, 'metadata')

            def _process(json):
                data = json.get('data')
                metadata = Metadata(data, session, resource_path)
                if self.is_singleton():
                    setattr(metadata, '_singleton', True)
                return metadata

            return session.get(url, CB.json(200, _process))

        method.__doc__ = method_doc
        setattr(cls, 'metadata', method)
        return cls

    return method_builder