Module: ResqueScheduler::Plugin

Extended by:
Plugin
Included in:
Plugin
Defined in:
lib/resque_scheduler/plugin.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/resque_scheduler/plugin.rb', line 16

def method_missing(method_name, *args, &block)
  if method_name.to_s =~ /^run_(.*)_hooks$/
    job = args.shift
    run_hooks job, $1, *args
  else
    super
  end
end

Instance Method Details

#hooks(job, pattern) ⇒ Object



4
5
6
# File 'lib/resque_scheduler/plugin.rb', line 4

def hooks(job, pattern)
  job.methods.grep(/^#{pattern}/).sort
end

#run_hooks(job, pattern, *args) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/resque_scheduler/plugin.rb', line 8

def run_hooks(job, pattern, *args)
  results = hooks(job, pattern).collect do |hook|
    job.send(hook, *args)
  end

  results.all? { |result| result != false }
end