# Path: elasticmagic/compat.py
# def with_metaclass(meta, *bases):
#     class metaclass(meta):
#         __call__ = type.__call__
#         __init__ = type.__init__
# 
#         def __new__(cls, name, this_bases, d):
#             if this_bases is None:
#                 return type.__new__(cls, name, (), d)
#             return meta(name, bases, d)
# 
#     return metaclass('temporary_class', None, {})
# 
# Path: elasticmagic/document.py
# class DynamicDocument(with_metaclass(DynamicDocumentMeta, Document)):
#     def _process_source_key_value(self, key, value):
#         key, value = (
#             super(DynamicDocument, self)._process_source_key_value(key, value)
#         )
#         if isinstance(value, dict):
#             return key, DynamicDocument(**value)
#         return key, value
# 
# Path: elasticmagic/util.py
# def to_camel_case(s):
#     return u''.join(map(lambda w: w.capitalize(), s.split('_')))


from abc import ABCMeta
from .compat import with_metaclass
from .document import DynamicDocument
from .util import to_camel_case
from __future__ import absolute_import




class BaseIndex(with_metaclass(ABCMeta)):
    def __init__(self, cluster, name):
        self._cluster = cluster
        self._name = name

        self._doc_cls_cache = {}

    def __getitem__(self, doc_type):
        return self.get_doc_cls(doc_type)

    def get_doc_cls(self, doc_type):
        if doc_type not in self._doc_cls_cache:
            self._doc_cls_cache[doc_type] = type(
                '{}{}'.format(to_camel_case(doc_type), 'Document'),
                (DynamicDocument,),
                {'__doc_type__': doc_type}
            )

# Path: elasticmagic/compat.py
# def with_metaclass(meta, *bases):
#     class metaclass(meta):
#         __call__ = type.__call__
#         __init__ = type.__init__
# 
#         def __new__(cls, name, this_bases, d):
#             if this_bases is None:
#                 return type.__new__(cls, name, (), d)
#             return meta(name, bases, d)
# 
#     return metaclass('temporary_class', None, {})
# 
# Path: elasticmagic/document.py
# class DynamicDocument(with_metaclass(DynamicDocumentMeta, Document)):
#     def _process_source_key_value(self, key, value):
#         key, value = (
#             super(DynamicDocument, self)._process_source_key_value(key, value)
#         )
#         if isinstance(value, dict):
#             return key, DynamicDocument(**value)
#         return key, value
# 
# Path: elasticmagic/util.py
# def to_camel_case(s):
#     return u''.join(map(lambda w: w.capitalize(), s.split('_')))


# Path: elasticmagic/index.py
from abc import ABCMeta
from .compat import with_metaclass
from .document import DynamicDocument
from .util import to_camel_case

from __future__ import absolute_import




class BaseIndex(with_metaclass(ABCMeta)):
    def __init__(self, cluster, name):
        self._cluster = cluster
        self._name = name

        self._doc_cls_cache = {}

    def __getitem__(self, doc_type):
        return self.get_doc_cls(doc_type)

    def get_doc_cls(self, doc_type):
        if doc_type not in self._doc_cls_cache:
            self._doc_cls_cache[doc_type] = type(
                '{}{}'.format(to_camel_case(doc_type), 'Document'),
                (DynamicDocument,),
                {'__doc_type__': doc_type}
            )

        return self._doc_cls_cache[doc_type]