Class: MetaRake::Task

Inherits:
Rake::Task
  • Object
show all
Includes:
FileUtils
Defined in:
lib/metarake/task.rb

Overview

An abstract Rake task that builds a project if it is not published. The individual methods need to be implemented in a subclass. Concrete implementation are provided in Builder and Publisher modules. Complete sample Rakefiles are included in the examples directory.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Task

Automatically add action calling the #build method if it’s dtefined.



52
53
54
55
# File 'lib/metarake/task.rb', line 52

def initialize(*args)
  super
  @actions << lambda { |t| t.build } if self.respond_to?(:build)
end

Class Method Details

.discover!Enumerable

Discover projects and build tasks for them.

Returns:

  • (Enumerable)

    tasks defined for each of projects returned by #projects

See Also:

  • #projects


25
26
27
28
29
30
31
# File 'lib/metarake/task.rb', line 25

def discover!
  projects.map do |prj|
    t = Rake.application.define_task(self, prj)
    t.comment = "Build #{prj}"
    t
  end
end

.projectsEnumerable

This method is abstract.

Discover projects to build.

Returns discovered project names.

Returns:

  • (Enumerable)

    discovered project names

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/metarake/task.rb', line 17

def projects
  raise NotImplementedError
end

Instance Method Details

#execute(*args) ⇒ Object

Publish the project after executing the task.



63
64
65
66
67
68
69
70
# File 'lib/metarake/task.rb', line 63

def execute(*args)
  super
  if application.options.dryrun
    $stderr.puts "** Publish (dry run) #{name}"
  else
    self.publish!
  end
end

#needed?Boolean

Project is “needed” only if it’s not published.

Returns:

  • (Boolean)


58
59
60
# File 'lib/metarake/task.rb', line 58

def needed?
  !self.published?
end

#publish!Object

This method is abstract.

Publishes the project

Runs after the project has been built in order to publish the build artifacts.

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/metarake/task.rb', line 42

def publish!
  raise NotImplementedError
end

#published?TrueClass, FalseClass

This method is abstract.

Check whether the project has been published

Returns True if project is already published and doesn’t need to be rebuilt.

Returns:

  • (TrueClass, FalseClass)

    True if project is already published and doesn’t need to be rebuilt.

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/metarake/task.rb', line 36

def published?
  raise NotImplementedError
end

#targetsObject

This method is abstract.

Array of project’s targets

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/metarake/task.rb', line 47

def targets
  raise NotImplementedError
end