freelancing-god-thinking-sphinx 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,7 +38,7 @@ module ThinkingSphinx
38
38
  module Version #:nodoc:
39
39
  Major = 1
40
40
  Minor = 2
41
- Tiny = 2
41
+ Tiny = 3
42
42
 
43
43
  String = [Major, Minor, Tiny].join('.')
44
44
  end
@@ -227,6 +227,18 @@ module ThinkingSphinx
227
227
  client
228
228
  end
229
229
 
230
+ def models_by_crc
231
+ @models_by_crc ||= begin
232
+ ThinkingSphinx.indexed_models.inject({}) do |hash, model|
233
+ hash[model.constantize.to_crc32] = model
234
+ Object.subclasses_of(model.constantize).each { |subclass|
235
+ hash[subclass.to_crc32] = subclass.name
236
+ }
237
+ hash
238
+ end
239
+ end
240
+ end
241
+
230
242
  private
231
243
 
232
244
  # Parse the config/sphinx.yml file - if it exists - then use the attribute
@@ -493,10 +493,10 @@ module ThinkingSphinx
493
493
  return {} unless options[:geo] || (options[:lat] && options[:lng])
494
494
 
495
495
  {
496
- :latitude => options[:geo] ? options[:geo].first : options[:lat],
497
- :longitude => options[:geo] ? options[:geo].last : options[:lng],
498
- :latitude_attr => latitude_attr,
499
- :longitude_attr => longitude_attr
496
+ :latitude => options[:geo] ? options[:geo].first : options[:lat],
497
+ :longitude => options[:geo] ? options[:geo].last : options[:lng],
498
+ :latitude_attribute => latitude_attr,
499
+ :longitude_attribute => longitude_attr
500
500
  }
501
501
  end
502
502
 
@@ -602,16 +602,7 @@ module ThinkingSphinx
602
602
  end
603
603
 
604
604
  def class_from_crc(crc)
605
- @models_by_crc ||= begin
606
- ThinkingSphinx.indexed_models.inject({}) do |hash, model|
607
- hash[model.constantize.to_crc32] = model
608
- Object.subclasses_of(model.constantize).each { |subclass|
609
- hash[subclass.to_crc32] = subclass.name
610
- }
611
- hash
612
- end
613
- end
614
- @models_by_crc[crc].constantize
605
+ config.models_by_crc[crc].constantize
615
606
  end
616
607
 
617
608
  def each_with_attribute(attribute, &block)
@@ -244,4 +244,19 @@ describe ThinkingSphinx::Configuration do
244
244
  @config.client.max_matches.should == 100
245
245
  end
246
246
  end
247
+
248
+ describe '#models_by_crc' do
249
+ before :each do
250
+ @config = ThinkingSphinx::Configuration.instance
251
+ end
252
+
253
+ it "should return a hash" do
254
+ @config.models_by_crc.should be_a(Hash)
255
+ end
256
+
257
+ it "should pair class names to their crc codes" do
258
+ @config.models_by_crc[Person.to_crc32].should == 'Person'
259
+ @config.models_by_crc[Alpha.to_crc32].should == 'Alpha'
260
+ end
261
+ end
247
262
  end
@@ -563,8 +563,8 @@ describe ThinkingSphinx::Search do
563
563
  :classes => [Alpha]
564
564
  ).first
565
565
 
566
- @client.anchor[:latitude_attr].should == :lat
567
- @client.anchor[:longitude_attr].should == :lng
566
+ @client.anchor[:latitude_attribute].should == :lat
567
+ @client.anchor[:longitude_attribute].should == :lng
568
568
  end
569
569
 
570
570
  it "should detect lat and lon attributes on the given model" do
@@ -573,8 +573,8 @@ describe ThinkingSphinx::Search do
573
573
  :classes => [Beta]
574
574
  ).first
575
575
 
576
- @client.anchor[:latitude_attr].should == :lat
577
- @client.anchor[:longitude_attr].should == :lon
576
+ @client.anchor[:latitude_attribute].should == :lat
577
+ @client.anchor[:longitude_attribute].should == :lon
578
578
  end
579
579
 
580
580
  it "should detect latitude and longitude attributes on the given model" do
@@ -583,8 +583,8 @@ describe ThinkingSphinx::Search do
583
583
  :classes => [Person]
584
584
  ).first
585
585
 
586
- @client.anchor[:latitude_attr].should == :latitude
587
- @client.anchor[:longitude_attr].should == :longitude
586
+ @client.anchor[:latitude_attribute].should == :latitude
587
+ @client.anchor[:longitude_attribute].should == :longitude
588
588
  end
589
589
 
590
590
  it "should accept manually defined latitude and longitude attributes" do
@@ -595,8 +595,8 @@ describe ThinkingSphinx::Search do
595
595
  :longitude_attr => :leftright
596
596
  ).first
597
597
 
598
- @client.anchor[:latitude_attr].should == :updown
599
- @client.anchor[:longitude_attr].should == :leftright
598
+ @client.anchor[:latitude_attribute].should == :updown
599
+ @client.anchor[:longitude_attribute].should == :leftright
600
600
  end
601
601
 
602
602
  it "should accept manually defined latitude and longitude attributes in the given model" do
@@ -605,8 +605,8 @@ describe ThinkingSphinx::Search do
605
605
  :classes => [Friendship]
606
606
  ).first
607
607
 
608
- @client.anchor[:latitude_attr].should == :person_id
609
- @client.anchor[:longitude_attr].should == :person_id
608
+ @client.anchor[:latitude_attribute].should == :person_id
609
+ @client.anchor[:longitude_attribute].should == :person_id
610
610
  end
611
611
 
612
612
  it "should accept geo array for geo-position values" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freelancing-god-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan