Class: Evoker::EntityTask

Inherits:
Rake::FileTask
  • Object
show all
Defined in:
lib/evoker.rb

Overview

Specialized task class for downloaded entities

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ EntityTask

Returns a new instance of EntityTask.


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/evoker.rb', line 30

def initialize(*args, &block)
  super(*args, &block)
  @stampname = "#{@name}.stamp"
  @actions << lambda { |*args| FileUtils::rm_rf @name }
  CLOBBER.add([@stampname, @name])
  ENTITIES.add(@name)

  if File.exists? "#{@name}.yaml"
    require 'yaml'
    @config = YAML::load_file("#{@name}.yaml")
    self.enhance [Rake.application.intern(Rake::FileTask, "#{@name}.yaml")]
  end
end

Instance Attribute Details

#configObject (readonly)

Parsed yaml config for the task


28
29
30
# File 'lib/evoker.rb', line 28

def config
  @config
end

Instance Method Details

#execute(args = nil) ⇒ Object

Executes task and writes its timestamp file


45
46
47
48
# File 'lib/evoker.rb', line 45

def execute(args=nil)
  super
  File.open(@stampname, 'w') { |f| f.write(DateTime::now.to_s) }
end

#needed?Boolean

Use @stampname instead of task name to determine whether to re-do the task

Returns:

  • (Boolean)

51
52
53
# File 'lib/evoker.rb', line 51

def needed?
  ! File.exist?(name) || ! File.exist?(@stampname) || out_of_date?(timestamp)
end

#timestampObject

Time stamp for file task is on the stamp file, not on target.


56
57
58
59
60
61
62
# File 'lib/evoker.rb', line 56

def timestamp
  if File.exist?(@stampname)
    File.mtime(@stampname)
  else
    Rake::EARLY
  end
end