Class: ThinkingSphinx::Subscribers::PopulatorSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/subscribers/populator_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attach_to(namespace) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/thinking_sphinx/subscribers/populator_subscriber.rb', line 4

def self.attach_to(namespace)
  subscriber = new

  subscriber.public_methods(false).each do |event|
    next if event == :call

    ActiveSupport::Notifications.subscribe(
      "#{event}.#{namespace}", subscriber
    )
  end
end

Instance Method Details

#call(message, *args) ⇒ Object



16
17
18
19
# File 'lib/thinking_sphinx/subscribers/populator_subscriber.rb', line 16

def call(message, *args)
  send message.split('.').first,
    ActiveSupport::Notifications::Event.new(message, *args)
end

#error(event) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/thinking_sphinx/subscribers/populator_subscriber.rb', line 21

def error(event)
  error    = event.payload[:error].inner_exception
  instance = event.payload[:error].instance

  puts <<-MESSAGE

Error transcribing #{instance.class} #{instance.id}:
#{error.message}
  MESSAGE
end

#finish_populating(event) ⇒ Object



40
41
42
# File 'lib/thinking_sphinx/subscribers/populator_subscriber.rb', line 40

def finish_populating(event)
  print "\n"
end

#populated(event) ⇒ Object



36
37
38
# File 'lib/thinking_sphinx/subscribers/populator_subscriber.rb', line 36

def populated(event)
  print '.' * event.payload[:instances].length
end

#start_populating(event) ⇒ Object



32
33
34
# File 'lib/thinking_sphinx/subscribers/populator_subscriber.rb', line 32

def start_populating(event)
  puts "Generating index files for #{event.payload[:index].name}"
end