Class: ASRake::VersionTask
- Inherits:
-
Object
- Object
- ASRake::VersionTask
- Includes:
- Rake::DSL
- Defined in:
- lib/asrake/version_task.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#filetype ⇒ Object
Returns the value of attribute filetype.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(name = :version, filename = "VERSION") {|_self| ... } ⇒ VersionTask
constructor
A new instance of VersionTask.
Constructor Details
#initialize(name = :version, filename = "VERSION") {|_self| ... } ⇒ VersionTask
Returns a new instance of VersionTask.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/asrake/version_task.rb', line 12 def initialize(name = :version, filename = "VERSION") self.filename = filename yield self if block_given? # fail if no filename was provided fail "You must define 'filename' for #{self}" if filename == nil @path = Pathname.new(self.filename) # set filetype from the filename if it hasn't been set already self.filetype ||= @path.extname[1..-1] # read in the current version contents = @path.read rescue '0.0.0' @version = case filetype.to_s when '' then Version.to_version(contents.chomp) when 'yml' then Version.to_version(YAML::load(contents)) end # create the primary version task desc "Increment version from #{@version}" @version_task = Rake::Task.define_task name # if the task name is a hash (ie, has dependencies defined) make sure we pull out the task name from it name, _ = name.first if name.is_a? Hash Rake::Task.define_task name, [:part] => filename do |t, args| case (args[:part] || "").chomp.downcase when 'major' puts "Incremented version from #{@version} to #{save(@version.bump!(:major))}" when 'minor' puts "Incremented version from #{@version} to #{save(@version.bump!(:minor))}" when 'revision', 'rev', 'patch' puts "Incremented version from #{@version} to #{save(@version.bump!(:revision))}" when '' puts "Current version is #{@version}" puts "Version number format is Major.Minor.Revision (aka Major.Minor.Patch)" puts "To increment the version, provide the respective part as an argument." puts "rake #{@version_task}[major] => #{@version.bump(:major)}" puts "rake #{@version_task}[minor] => #{@version.bump(:minor)}" puts "rake #{@version_task}[revision] => #{@version.bump(:revision)}" else fail "Invalid version argument '#{args[:part]}', run 'rake #{@version_task}' for help." end @sync_task.execute() end file filename do puts "Created version #{save(Version.to_version(ENV['VERSION'] || '0.0.0'))} at #{filename}" end # create a namespace with the same name as the task to provide further options namespace name do #add to this task to perform some operation post-bump @sync_task = task :sync end end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
8 9 10 |
# File 'lib/asrake/version_task.rb', line 8 def filename @filename end |
#filetype ⇒ Object
Returns the value of attribute filetype.
9 10 11 |
# File 'lib/asrake/version_task.rb', line 9 def filetype @filetype end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
10 11 12 |
# File 'lib/asrake/version_task.rb', line 10 def version @version end |