Module: Sake::Store

Extended by:
Store
Included in:
Store
Defined in:
lib/sake.rb

Overview

The store is, as of writing, a single Rakefile: ~/.sake When we add new tasks, we just re-build this file. Over and over.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Everything we can’t catch gets sent to our tasks_file. Common examples are #tasks or #add_task.



488
489
490
# File 'lib/sake.rb', line 488

def method_missing(*args, &block)
  tasks_file.send(*args, &block)
end

Instance Method Details

#pathObject

The platform-aware path to the Store



500
501
502
503
504
505
506
507
508
# File 'lib/sake.rb', line 500

def path
  path = if PLATFORM =~ /win32/
    win32_path
  else
    File.join(File.expand_path('~'), '.sake')
  end
  FileUtils.touch(path) unless path.is_file?
  path
end

#save!Object

Wrote our current tasks_file to disk, overwriting the current Store.



521
522
523
524
525
526
# File 'lib/sake.rb', line 521

def save!
  tasks_file # ensure the tasks_file is loaded before overwriting
  File.open(path, 'w') do |file|
    file.puts tasks_file.to_ruby
  end
end

#tasks_fileObject

A TaskFile object of our Store



494
495
496
# File 'lib/sake.rb', line 494

def tasks_file
  @tasks_file ||= TasksFile.parse(path)
end

#win32_pathObject

:nodoc:



510
511
512
513
514
515
516
517
# File 'lib/sake.rb', line 510

def win32_path #:nodoc:
  unless File.exists?(win32home = ENV['HOMEDRIVE'] + ENV['HOMEPATH'])
    puts "# No HOMEDRIVE or HOMEPATH environment variable.",  
         "# Sake needs to know where it should save Rake tasks!"
  else
    File.join(win32home, 'Sakefile')
  end
end