Class: ThinkingSphinx::Callbacks

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

Defined Under Namespace

Classes: Appender

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ Callbacks

Returns a new instance of Callbacks.



39
40
41
# File 'lib/thinking_sphinx/callbacks.rb', line 39

def initialize(instance)
  @instance = instance
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'lib/thinking_sphinx/callbacks.rb', line 4

def instance
  @instance
end

Class Method Details

.append(model, reference = nil, options, &block) ⇒ Object



6
7
8
9
10
11
# File 'lib/thinking_sphinx/callbacks.rb', line 6

def self.append(model, reference = nil, options, &block)
  reference ||= ThinkingSphinx::Configuration.instance.index_set_class.
    reference_name(model)

  ThinkingSphinx::Callbacks::Appender.call(model, reference, options, &block)
end

.callbacks(*methods) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/thinking_sphinx/callbacks.rb', line 13

def self.callbacks(*methods)
  mod = Module.new
  methods.each do |method|
    mod.send(:define_method, method) { |instance| new(instance).send(method) }
  end
  extend mod
end

.resume!Object



21
22
23
# File 'lib/thinking_sphinx/callbacks.rb', line 21

def self.resume!
  @suspended = false
end

.suspend(&block) ⇒ Object



25
26
27
28
29
# File 'lib/thinking_sphinx/callbacks.rb', line 25

def self.suspend(&block)
  suspend!
  yield
  resume!
end

.suspend!Object



31
32
33
# File 'lib/thinking_sphinx/callbacks.rb', line 31

def self.suspend!
  @suspended = true
end

.suspended?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/thinking_sphinx/callbacks.rb', line 35

def self.suspended?
  @suspended
end