Class: Enrar::Task

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/enrar/task.rb

Overview

Create the Enrar Rake tasks programmatically. This code was shamelessly stolen and modified from the Rake library.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :enrar) {|_self| ... } ⇒ Task

Create the Enrar tasks

Yields:

  • (_self)

Yield Parameters:

  • _self (Enrar::Task)

    the object that the method was called on



21
22
23
24
25
26
27
# File 'lib/enrar/task.rb', line 21

def initialize(name=:enrar)
  @name = name
  @database_config = 'config/database.yml'
  @verbose = verbose
  yield self if block_given?
  define
end

Instance Attribute Details

#database_configObject

The path to your database.yml file. (default is config/database.yml)



15
16
17
# File 'lib/enrar/task.rb', line 15

def database_config
  @database_config
end

#nameObject

Name of test task. (default is :enrar)



12
13
14
# File 'lib/enrar/task.rb', line 12

def name
  @name
end

#verboseObject

Do you want me to be noisy?



18
19
20
# File 'lib/enrar/task.rb', line 18

def verbose
  @verbose
end

Instance Method Details

#defineObject

Create the tasks defined by this task lib.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/enrar/task.rb', line 30

def define
  desc "Generate a migration (don't forget to pass the migration name)"
  task "#{@name}:migrations:generate", [:name] do |t, args|
    raise 'Need a migration name' unless args[:name]
    Enrar::Migration.new(args[:name]).generate!
  end

  desc "Create the db"
  task "#{@name}:db:create" do
    Enrar::DB.new.create!
  end

  desc "Migrate the database (VERBOSE=true)"
  task "#{@name}:db:migrate", [:version] do |t, args|
    Enrar::Migrator.new(args[:version], verbose: ENV['VERBOSE']).migrate!
  end
  self
end