Module: RubyClock::Rake

Included in:
RubyClock
Defined in:
lib/ruby-clock/rake.rb

Overview

Instance Method Summary collapse

Instance Method Details

#prepare_rakeObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ruby-clock/rake.rb', line 3

def prepare_rake
  if defined?(::Rails) && Rails.application
    Rails.application.load_tasks
    Rake::Task.tasks.each{|t| t.prerequisites.delete 'environment' }
    @rake_mutex = Mutex.new
  else
    puts <<~MESSAGE
      Because this is not a rails application, we do not know how to load your
      rake tasks. You can do this yourself at the top of your Clockfile if you want
      to run rake tasks from ruby-clock.
    MESSAGE
  end
end

#rake(task) ⇒ Object

If the task has shared dependencies and you might run more than one at the same time This is the safest option and hence the default.



33
34
35
# File 'lib/ruby-clock/rake.rb', line 33

def rake(task)
  @rake_mutex.synchronize { rake_async(task) }
end

#rake_async(task) ⇒ Object

If the task doesn’t share dependencies with another task, or if it does and you know you’ll never run tasks such that any overlap



24
25
26
27
28
29
# File 'lib/ruby-clock/rake.rb', line 24

def rake_async(task)
  Rake::Task[task].invoke
ensure
  Rake::Task[task].reenable
  Rake::Task[task].all_prerequisite_tasks.each(&:reenable)
end

#rake_execute(task) ⇒ Object

for tasks that don’t have dependencies



18
19
20
# File 'lib/ruby-clock/rake.rb', line 18

def rake_execute(task)
  Rake::Task[task].execute
end