Class: ThinkingSphinx::ActiveRecord::FilteredReflection::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/active_record/filtered_reflection.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Filter) initialize(reflection, class_name)

Returns a new instance of Filter



9
10
11
12
# File 'lib/thinking_sphinx/active_record/filtered_reflection.rb', line 9

def initialize(reflection, class_name)
  @reflection, @class_name = reflection, class_name
  @options = reflection.options.clone
end

Instance Attribute Details

- (Object) class_name (readonly)

Returns the value of attribute class_name



5
6
7
# File 'lib/thinking_sphinx/active_record/filtered_reflection.rb', line 5

def class_name
  @class_name
end

- (Object) reflection (readonly)

Returns the value of attribute reflection



5
6
7
# File 'lib/thinking_sphinx/active_record/filtered_reflection.rb', line 5

def reflection
  @reflection
end

Instance Method Details

- (Object) options



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/thinking_sphinx/active_record/filtered_reflection.rb', line 14

def options
  @options.delete :polymorphic
  @options[:class_name]    = class_name
  @options[:foreign_key] ||= "#{reflection.name}_id"
  @options[:foreign_type]  = reflection.foreign_type

  return @options if reflection.respond_to?(:scope)

  case @options[:conditions]
  when nil
    @options[:conditions] = condition
  when Array
    @options[:conditions] << condition
  when Hash
    @options[:conditions].merge!(reflection.foreign_type => @options[:class_name])
  else
    @options[:conditions] << " AND #{condition}"
  end

  @options
end

- (Object) scope



36
37
38
39
40
41
42
43
44
# File 'lib/thinking_sphinx/active_record/filtered_reflection.rb', line 36

def scope
  lambda { |association|
    reflection = association.reflection
    where(
      association.parent.aliased_table_name.to_sym =>
      {reflection.foreign_type => reflection.class_name}
    )
  }
end