mebla 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mebla (1.0.0)
4
+ mebla (1.0.1)
5
5
  bson (= 1.2.0)
6
6
  bson_ext (= 1.2.0)
7
7
  mebla
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
data/lib/mebla/context.rb CHANGED
@@ -16,7 +16,7 @@ module Mebla
16
16
 
17
17
  # @private
18
18
  # Adds a model to the list of indexed models
19
- def add_indexed_model(model, mappings = {})
19
+ def add_indexed_model(model, mappings = {})
20
20
  model = model.name if model.is_a?(Class)
21
21
 
22
22
  @indexed_models << model
@@ -91,7 +91,7 @@ module Mebla
91
91
  only_index = @indexed_models
92
92
  else
93
93
  only_index = models.collect{|m| m.to_s}
94
- end
94
+ end
95
95
 
96
96
  Mebla.log("Indexing #{only_index.join(", ")}", :debug)
97
97
 
@@ -111,25 +111,34 @@ module Mebla
111
111
  # Get the records
112
112
  entries = []
113
113
  unless to_index.embedded?
114
- entries = to_index.all.only(to_index.search_fields)
114
+ if to_index.sub_class?
115
+ entries = to_index.any_in(:_type => [to_index.name]).only(to_index.search_fields)
116
+ else
117
+ entries = to_index.any_in(:_type => [nil, to_index.name]).only(to_index.search_fields)
118
+ end
115
119
  else
116
120
  parent = to_index.embedded_parent
117
121
  access_method = to_index.embedded_as
118
122
 
119
- parent.all.each do |parent_record|
120
- entries += parent_record.send(access_method.to_sym).all.only(to_index.search_fields)
123
+ parent.all.each do |parent_record|
124
+ if to_index.sub_class?
125
+ entries += parent_record.send(access_method.to_sym).any_in(:_type => [to_index.name]).only(to_index.search_fields)
126
+ else
127
+ entries += parent_record.send(access_method.to_sym).any_in(:_type => [nil, to_index.name]).only(to_index.search_fields)
128
+ end
121
129
  end
122
130
  end
123
131
 
124
132
  # Save the number of entries to be indexed
125
- indexed_count[model] = entries.count
133
+ indexed_count[model] = entries.count
126
134
 
127
135
  # Build the queries for this model
128
136
  entries.each do |document|
129
137
  attrs = document.attributes.dup # make sure we dont modify the document it self
130
138
  attrs["id"] = attrs.delete("_id") # the id is already added in the meta data of the action part of the query
131
139
 
132
- # only index search fields
140
+
141
+ # only index search fields
133
142
  attrs.select!{|field, value| document.class.search_fields.include?(field.to_sym)}
134
143
 
135
144
  # If embedded get the parent id
@@ -95,7 +95,7 @@ module Mongoid
95
95
  raise ::Mebla::Errors::MeblaConfigurationException.new("Couldn't infer #{embedor.to_s} inverse relation, please set :inverse_of option on the relation.")
96
96
  end
97
97
  else
98
- raise ::Mebla::Errors::MeblaConfigurationException.new("#{self.model_name} is embedded: embedded_in option should be set to the parent class if the document is embedded.")
98
+ raise ::Mebla::Errors::MeblaConfigurationException.new("#{self.name} is embedded: embedded_in option should be set to the parent class if the document is embedded.")
99
99
  end
100
100
  end
101
101
 
@@ -157,6 +157,12 @@ module Mongoid
157
157
  set_callback(:destroy, :before, :remove_from_index)
158
158
  end
159
159
 
160
+ # Checks if the class is a subclass
161
+ # @return [Boolean] true if class is a subclass
162
+ def sub_class?
163
+ self.superclass != Object
164
+ end
165
+
160
166
  private
161
167
  # Prepare the mappings required for this document
162
168
  # @return [Hash]
data/mebla.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mebla}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Omar Mekky"]
12
- s.date = %q{2011-03-18}
12
+ s.date = %q{2011-03-22}
13
13
  s.description = %q{
14
14
  An elasticsearch wrapper for mongoid odm based on slingshot. Makes integration between ElasticSearch full-text
15
15
  search engine and Mongoid documents seemless and simple.
@@ -154,6 +154,14 @@ Gem::Specification.new do |s|
154
154
  s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
155
155
  s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
156
156
  s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
157
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
158
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
159
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
160
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
161
+ s.add_development_dependency(%q<rcov>, [">= 0"])
162
+ s.add_development_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
163
+ s.add_development_dependency(%q<database_cleaner>, ["= 0.6.4"])
164
+ s.add_development_dependency(%q<bluecloth>, ["~> 2.1.0"])
157
165
  s.add_runtime_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
158
166
  s.add_runtime_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
159
167
  s.add_runtime_dependency(%q<bson>, ["= 1.2.0"])
@@ -241,6 +249,14 @@ Gem::Specification.new do |s|
241
249
  s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
242
250
  s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
243
251
  s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
252
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
253
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
254
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
255
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
256
+ s.add_dependency(%q<rcov>, [">= 0"])
257
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
258
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
259
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
244
260
  s.add_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
245
261
  s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
246
262
  s.add_dependency(%q<bson>, ["= 1.2.0"])
@@ -329,6 +345,14 @@ Gem::Specification.new do |s|
329
345
  s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
330
346
  s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
331
347
  s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
348
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
349
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
350
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
351
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
352
+ s.add_dependency(%q<rcov>, [">= 0"])
353
+ s.add_dependency(%q<mongoid-rspec>, ["= 1.4.1"])
354
+ s.add_dependency(%q<database_cleaner>, ["= 0.6.4"])
355
+ s.add_dependency(%q<bluecloth>, ["~> 2.1.0"])
332
356
  s.add_dependency(%q<slingshot-rb>, ["~> 0.0.6"])
333
357
  s.add_dependency(%q<mongoid>, ["= 2.0.0.rc.7"])
334
358
  s.add_dependency(%q<bson>, ["= 1.2.0"])
@@ -29,6 +29,20 @@ class MongoidTheta < MongoidAlpha
29
29
  search_in :extra
30
30
  end
31
31
 
32
+ class MongoidTau < MongoidAlpha
33
+ field :extra2
34
+ end
35
+
36
+ class MongoidDelta
37
+ include Mongoid::Document
38
+ include Mongoid::Mebla
39
+ field :name
40
+ end
41
+
42
+ class MongoidOmega < MongoidDelta
43
+ search_in :name
44
+ end
45
+
32
46
  class MongoidGamma
33
47
  include Mongoid::Document
34
48
  include Mongoid::Mebla
@@ -17,7 +17,7 @@ describe "Mebla" do
17
17
 
18
18
  lambda {Mebla.context.slingshot_index.retrieve(:mongoid_alpha, fdocument.id.to_s)}.should_not raise_error
19
19
  lambda {Mebla.context.slingshot_index.retrieve(:mongoid_alpha, ldocument.id.to_s)}.should_not raise_error
20
- end
20
+ end
21
21
 
22
22
  it "should delete the existing index and create a new one" do
23
23
  Mebla.context.rebuild_index.should_not == false
@@ -30,7 +30,48 @@ describe "Mebla" do
30
30
  maps["cost"]["type"].should == "float"
31
31
  end
32
32
 
33
- describe "embedded documents" do
33
+ describe "for sub-classed documents" do
34
+ it "should index existing records" do
35
+ Mebla.context.drop_index
36
+
37
+ theta = nil
38
+
39
+ MongoidTheta.without_indexing do
40
+ theta = MongoidTheta.create! :extra => "Subclassed parent"
41
+ end
42
+
43
+ Mebla.context.index_data
44
+
45
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_theta, theta.id.to_s)}.should_not raise_error
46
+ end
47
+
48
+ it "should not index non searchable subclassed models" do
49
+ Mebla.context.drop_index
50
+
51
+ tau = nil
52
+ MongoidAlpha.without_indexing do
53
+ MongoidAlpha.create! :name => "Testing indexing bulkly", :value => 1, :cost => 1.0
54
+ tau = MongoidTau.create! :extra2 => "Should not be indexed"
55
+ end
56
+
57
+ lambda {Mebla.context.index_data}.should_not raise_error
58
+ lambda {Mebla.context.slingshot_index.retrieve(:mongoid_tau, tau.id.to_s)}.should raise_error
59
+ end
60
+
61
+ it "should index only models with defined indecies" do
62
+ Mebla.context.drop_index
63
+
64
+ theta = nil
65
+
66
+ MongoidOmega.without_indexing do
67
+ theta = MongoidOmega.create! :name => "Subclassed parent"
68
+ end
69
+
70
+ lambda {Mebla.context.index_data}.should_not raise_error
71
+ end
72
+ end
73
+
74
+ describe "for embedded documents" do
34
75
  it "should index existing records" do
35
76
  Mebla.context.drop_index
36
77
 
@@ -42,7 +83,7 @@ describe "Mebla" do
42
83
  MongoidGamma.without_indexing do
43
84
  gamma = beta.mongoid_gammas.create :name => "Embedded", :value => 1
44
85
  end
45
- end
86
+ end
46
87
 
47
88
  Mebla.context.index_data
48
89
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mebla
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.1
5
+ version: 1.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Omar Mekky
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-18 00:00:00 +02:00
13
+ date: 2011-03-22 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -828,8 +828,96 @@ dependencies:
828
828
  prerelease: false
829
829
  version_requirements: *id074
830
830
  - !ruby/object:Gem::Dependency
831
- name: slingshot-rb
831
+ name: rspec
832
832
  requirement: &id075 !ruby/object:Gem::Requirement
833
+ none: false
834
+ requirements:
835
+ - - ~>
836
+ - !ruby/object:Gem::Version
837
+ version: 2.3.0
838
+ type: :development
839
+ prerelease: false
840
+ version_requirements: *id075
841
+ - !ruby/object:Gem::Dependency
842
+ name: yard
843
+ requirement: &id076 !ruby/object:Gem::Requirement
844
+ none: false
845
+ requirements:
846
+ - - ~>
847
+ - !ruby/object:Gem::Version
848
+ version: 0.6.0
849
+ type: :development
850
+ prerelease: false
851
+ version_requirements: *id076
852
+ - !ruby/object:Gem::Dependency
853
+ name: bundler
854
+ requirement: &id077 !ruby/object:Gem::Requirement
855
+ none: false
856
+ requirements:
857
+ - - ~>
858
+ - !ruby/object:Gem::Version
859
+ version: 1.0.0
860
+ type: :development
861
+ prerelease: false
862
+ version_requirements: *id077
863
+ - !ruby/object:Gem::Dependency
864
+ name: jeweler
865
+ requirement: &id078 !ruby/object:Gem::Requirement
866
+ none: false
867
+ requirements:
868
+ - - ~>
869
+ - !ruby/object:Gem::Version
870
+ version: 1.5.2
871
+ type: :development
872
+ prerelease: false
873
+ version_requirements: *id078
874
+ - !ruby/object:Gem::Dependency
875
+ name: rcov
876
+ requirement: &id079 !ruby/object:Gem::Requirement
877
+ none: false
878
+ requirements:
879
+ - - ">="
880
+ - !ruby/object:Gem::Version
881
+ version: "0"
882
+ type: :development
883
+ prerelease: false
884
+ version_requirements: *id079
885
+ - !ruby/object:Gem::Dependency
886
+ name: mongoid-rspec
887
+ requirement: &id080 !ruby/object:Gem::Requirement
888
+ none: false
889
+ requirements:
890
+ - - "="
891
+ - !ruby/object:Gem::Version
892
+ version: 1.4.1
893
+ type: :development
894
+ prerelease: false
895
+ version_requirements: *id080
896
+ - !ruby/object:Gem::Dependency
897
+ name: database_cleaner
898
+ requirement: &id081 !ruby/object:Gem::Requirement
899
+ none: false
900
+ requirements:
901
+ - - "="
902
+ - !ruby/object:Gem::Version
903
+ version: 0.6.4
904
+ type: :development
905
+ prerelease: false
906
+ version_requirements: *id081
907
+ - !ruby/object:Gem::Dependency
908
+ name: bluecloth
909
+ requirement: &id082 !ruby/object:Gem::Requirement
910
+ none: false
911
+ requirements:
912
+ - - ~>
913
+ - !ruby/object:Gem::Version
914
+ version: 2.1.0
915
+ type: :development
916
+ prerelease: false
917
+ version_requirements: *id082
918
+ - !ruby/object:Gem::Dependency
919
+ name: slingshot-rb
920
+ requirement: &id083 !ruby/object:Gem::Requirement
833
921
  none: false
834
922
  requirements:
835
923
  - - ~>
@@ -837,10 +925,10 @@ dependencies:
837
925
  version: 0.0.6
838
926
  type: :runtime
839
927
  prerelease: false
840
- version_requirements: *id075
928
+ version_requirements: *id083
841
929
  - !ruby/object:Gem::Dependency
842
930
  name: mongoid
843
- requirement: &id076 !ruby/object:Gem::Requirement
931
+ requirement: &id084 !ruby/object:Gem::Requirement
844
932
  none: false
845
933
  requirements:
846
934
  - - "="
@@ -848,10 +936,10 @@ dependencies:
848
936
  version: 2.0.0.rc.7
849
937
  type: :runtime
850
938
  prerelease: false
851
- version_requirements: *id076
939
+ version_requirements: *id084
852
940
  - !ruby/object:Gem::Dependency
853
941
  name: bson
854
- requirement: &id077 !ruby/object:Gem::Requirement
942
+ requirement: &id085 !ruby/object:Gem::Requirement
855
943
  none: false
856
944
  requirements:
857
945
  - - "="
@@ -859,10 +947,10 @@ dependencies:
859
947
  version: 1.2.0
860
948
  type: :runtime
861
949
  prerelease: false
862
- version_requirements: *id077
950
+ version_requirements: *id085
863
951
  - !ruby/object:Gem::Dependency
864
952
  name: bson_ext
865
- requirement: &id078 !ruby/object:Gem::Requirement
953
+ requirement: &id086 !ruby/object:Gem::Requirement
866
954
  none: false
867
955
  requirements:
868
956
  - - "="
@@ -870,10 +958,10 @@ dependencies:
870
958
  version: 1.2.0
871
959
  type: :runtime
872
960
  prerelease: false
873
- version_requirements: *id078
961
+ version_requirements: *id086
874
962
  - !ruby/object:Gem::Dependency
875
963
  name: rspec
876
- requirement: &id079 !ruby/object:Gem::Requirement
964
+ requirement: &id087 !ruby/object:Gem::Requirement
877
965
  none: false
878
966
  requirements:
879
967
  - - ~>
@@ -881,10 +969,10 @@ dependencies:
881
969
  version: 2.3.0
882
970
  type: :development
883
971
  prerelease: false
884
- version_requirements: *id079
972
+ version_requirements: *id087
885
973
  - !ruby/object:Gem::Dependency
886
974
  name: yard
887
- requirement: &id080 !ruby/object:Gem::Requirement
975
+ requirement: &id088 !ruby/object:Gem::Requirement
888
976
  none: false
889
977
  requirements:
890
978
  - - ~>
@@ -892,10 +980,10 @@ dependencies:
892
980
  version: 0.6.0
893
981
  type: :development
894
982
  prerelease: false
895
- version_requirements: *id080
983
+ version_requirements: *id088
896
984
  - !ruby/object:Gem::Dependency
897
985
  name: bundler
898
- requirement: &id081 !ruby/object:Gem::Requirement
986
+ requirement: &id089 !ruby/object:Gem::Requirement
899
987
  none: false
900
988
  requirements:
901
989
  - - ~>
@@ -903,10 +991,10 @@ dependencies:
903
991
  version: 1.0.0
904
992
  type: :development
905
993
  prerelease: false
906
- version_requirements: *id081
994
+ version_requirements: *id089
907
995
  - !ruby/object:Gem::Dependency
908
996
  name: jeweler
909
- requirement: &id082 !ruby/object:Gem::Requirement
997
+ requirement: &id090 !ruby/object:Gem::Requirement
910
998
  none: false
911
999
  requirements:
912
1000
  - - ~>
@@ -914,10 +1002,10 @@ dependencies:
914
1002
  version: 1.5.2
915
1003
  type: :development
916
1004
  prerelease: false
917
- version_requirements: *id082
1005
+ version_requirements: *id090
918
1006
  - !ruby/object:Gem::Dependency
919
1007
  name: rcov
920
- requirement: &id083 !ruby/object:Gem::Requirement
1008
+ requirement: &id091 !ruby/object:Gem::Requirement
921
1009
  none: false
922
1010
  requirements:
923
1011
  - - ">="
@@ -925,10 +1013,10 @@ dependencies:
925
1013
  version: "0"
926
1014
  type: :development
927
1015
  prerelease: false
928
- version_requirements: *id083
1016
+ version_requirements: *id091
929
1017
  - !ruby/object:Gem::Dependency
930
1018
  name: mongoid-rspec
931
- requirement: &id084 !ruby/object:Gem::Requirement
1019
+ requirement: &id092 !ruby/object:Gem::Requirement
932
1020
  none: false
933
1021
  requirements:
934
1022
  - - "="
@@ -936,10 +1024,10 @@ dependencies:
936
1024
  version: 1.4.1
937
1025
  type: :development
938
1026
  prerelease: false
939
- version_requirements: *id084
1027
+ version_requirements: *id092
940
1028
  - !ruby/object:Gem::Dependency
941
1029
  name: database_cleaner
942
- requirement: &id085 !ruby/object:Gem::Requirement
1030
+ requirement: &id093 !ruby/object:Gem::Requirement
943
1031
  none: false
944
1032
  requirements:
945
1033
  - - "="
@@ -947,10 +1035,10 @@ dependencies:
947
1035
  version: 0.6.4
948
1036
  type: :development
949
1037
  prerelease: false
950
- version_requirements: *id085
1038
+ version_requirements: *id093
951
1039
  - !ruby/object:Gem::Dependency
952
1040
  name: bluecloth
953
- requirement: &id086 !ruby/object:Gem::Requirement
1041
+ requirement: &id094 !ruby/object:Gem::Requirement
954
1042
  none: false
955
1043
  requirements:
956
1044
  - - ~>
@@ -958,7 +1046,7 @@ dependencies:
958
1046
  version: 2.1.0
959
1047
  type: :development
960
1048
  prerelease: false
961
- version_requirements: *id086
1049
+ version_requirements: *id094
962
1050
  description: "\n An elasticsearch wrapper for mongoid odm based on slingshot. Makes integration between ElasticSearch full-text \n search engine and Mongoid documents seemless and simple.\n "
963
1051
  email: omar.mekky@mashsolvents.com
964
1052
  executables: []
@@ -1021,7 +1109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1021
1109
  requirements:
1022
1110
  - - ">="
1023
1111
  - !ruby/object:Gem::Version
1024
- hash: 3644119659415680929
1112
+ hash: -1595562442589662284
1025
1113
  segments:
1026
1114
  - 0
1027
1115
  version: "0"