Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: foca/migrake
base: 4000408fc6
...
head fork: foca/migrake
compare: 285e70a8bf
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 15, 2012
@foca Don't commit the phoney MIGRAKE_STATUS from playing around dbb9115
@foca Added an example a0f3db3
@foca Documentation
And some minor adjustments (preserving the public API) while documenting
285e70a
View
1  .gitignore
@@ -0,0 +1 @@
+/MIGRAKE_STATUS
View
10 examples/Rakefile
@@ -0,0 +1,10 @@
+require "migrake"
+
+migrake Set.new(%w(a b c d))
+
+%w(a b c d).each do |t|
+ desc "Print #{t}"
+ task t do
+ puts t
+ end
+end
View
65 lib/migrake.rb
@@ -5,50 +5,77 @@
require "pathname"
module Migrake
+ # Public: Change the directory where we keep the MIGRAKE_STATUS file.
+ #
+ # dir - A filesystem path.
+ #
+ # Returns the directory path.
def self.status_file_directory=(dir)
@status_dir = Pathname(dir)
end
+ # Public: Get the directory where we keep the MIGRAKE_STATUS file. If no
+ # directory is set, we will try to fetch it from the ENV, using the
+ # MIGRAKE_STATUS_DIR environment variable. If that isn't set either, we
+ # default to the working directory.
+ #
+ # Returns a Pathname.
def self.status_file_directory
@status_dir ||= Pathname(ENV.fetch("MIGRAKE_STATUS_DIR", Dir.pwd))
end
- class Runner
+ # The Runner is responsible for selecting the rake tasks to be run and run
+ # them, unless they have already been run in this host.
+ module Runner
+ # Public: Run all the rake tasks in `set` that haven't been stored in
+ # `store`.
+ #
+ # set - A Set with tasks to be run.
+ # store - A Migrake::Store with the tasks that have already been run.
+ #
+ # Returns the Set of tasks that were run.
def self.run(set, store)
- new(set, store).run
- end
-
- attr :store
- attr :set
-
- def initialize(set, store)
- @set = set
- @store = store
- end
-
- def run
- set.each do |task|
- Rake::Task[task].invoke unless store.all.include?(task)
+ (set - store.all).each do |task|
+ Rake::Task[task].invoke
store.put(task)
end
end
end
+ # The Store handles the file where tasks that have already been run are stored
+ # so they aren't run again.
class Store
- def initialize(file)
- @file = file
+ # Public: Initialize the store.
+ #
+ # path - The path to the file where we store the information.
+ def initialize(path)
+ @path = path
end
+ # Public: Add one task to the store. This immediately writes the file to
+ # disk, to preserve consistency.
+ #
+ # task - A string with a task's name.
+ #
+ # Returns nil.
def put(task)
write(all << task)
end
+ # Public: Load all the tasks from the store.
+ #
+ # Returns a Set.
def all
- @all ||= YAML.load(@file.read) || Set.new
+ @all ||= YAML.load(@path.read) || Set.new
end
+ # Public: Write a whole set of tasks to the store, replacing what is in it.
+ #
+ # set - A Set of tasks.
+ #
+ # Returns nil.
def write(set)
- @file.open("w+") { |f| f.puts YAML.dump(set) }
+ @path.open("w+") { |f| f.puts YAML.dump(set) }
end
end
end
View
13 lib/migrake/dsl.rb
@@ -2,6 +2,19 @@
module Migrake
module DSL
+ # Public: Define the rake tasks required to run migrake. This defines the
+ # following tasks:
+ #
+ # - A task to create the `Migrake.status_file_directory` unless it exists.
+ # - A task to create the MIGRAKE_STATUS file in the aforementioned
+ # directory, unless it exists.
+ # - A `migrake:ready` task to bootstrap new environments by writing all
+ # the tasks to the store.
+ # - The `migrake` task, that will run any tasks not run before.
+ #
+ # tasks - A Set of tasks to be run.
+ #
+ # Returns the `migrake` Rake::Task.
def migrake(tasks)
dir = Migrake.status_file_directory
status_file = dir.join("MIGRAKE_STATUS")

No commit comments for this range

Something went wrong with that request. Please try again.