lycra 0.0.7 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/lycra/model.rb DELETED
@@ -1,62 +0,0 @@
1
- module Lycra
2
- module Model
3
- def self.included(base)
4
- base.send :extend, ClassMethods
5
- base.send :include, Elasticsearch::Model
6
- base.send :include, Elasticsearch::Model::Callbacks
7
-
8
- base.send :lycra_document
9
-
10
- base.send :delegate, :as_indexed_json, to: :lycra_document
11
- end
12
-
13
- def lycra_document
14
- self.class.lycra_document.new(self)
15
- end
16
-
17
- module ClassMethods
18
- def index_name(idx=nil)
19
- lycra_document.index_name idx
20
- end
21
-
22
- def document_type(doctype=nil)
23
- lycra_document.document_type doctype
24
- end
25
-
26
- def mapping(options={}, &block)
27
- lycra_document.mapping options, &block
28
- end
29
- alias_method :mappings, :mapping
30
-
31
- def lycra_document(klass=nil)
32
- if klass.present?
33
- if klass.respond_to?(:constantize)
34
- @lycra_document = klass.constantize.new(self)
35
- else
36
- @lycra_document = klass.new(self)
37
- end
38
- end
39
-
40
- @lycra_document ||= lycra_document_klass.new(self)
41
- end
42
-
43
- def lycra_document_klass
44
- begin
45
- return "#{self.name}Document".constantize
46
- rescue NameError => e
47
- # noop, we just continue
48
- end
49
-
50
- if respond_to?(:base_class) && self.base_class.name != self.name
51
- begin
52
- return "#{self.base_class.name}Document".constantize
53
- rescue NameError => e
54
- # noop, we just continue
55
- end
56
- end
57
-
58
- raise Lycra::DocumentNotFoundError.new(self)
59
- end
60
- end
61
- end
62
- end