Class: ActionScriptVersion::Task

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/shed/rake/version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Task.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
20
# File 'lib/shed/rake/version.rb', line 12

def initialize name = :version
  @name = name
  @output = 'Version.as'
  @strip_xml_comments = false

  yield self if block_given?

  define
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



5
6
7
# File 'lib/shed/rake/version.rb', line 5

def major
  @major
end

#minorObject

Returns the value of attribute minor.



5
6
7
# File 'lib/shed/rake/version.rb', line 5

def minor
  @minor
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/shed/rake/version.rb', line 5

def output
  @output
end

#patchObject

Returns the value of attribute patch.



5
6
7
# File 'lib/shed/rake/version.rb', line 5

def patch
  @patch
end

#strip_xml_commentsObject

Returns the value of attribute strip_xml_comments.



5
6
7
# File 'lib/shed/rake/version.rb', line 5

def strip_xml_comments
  @strip_xml_comments
end

#templateObject

Returns the value of attribute template.



5
6
7
# File 'lib/shed/rake/version.rb', line 5

def template
  @template
end

Instance Method Details

#defineObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/shed/rake/version.rb', line 22

def define
  desc "Generate a ActionScript class containing application version details"
  task @name do
    revision = `git rev-parse HEAD`.chomp rescue 'no-git-rev'
    t = File.read(@template)
    t.gsub!('@major@', major.to_s)
    t.gsub!('@minor@', minor.to_s)
    t.gsub!('@patch@', patch.to_s)
    t.gsub!('@revision@', revision)
    t = Stripper.xml_comments(t) if @strip_xml_comments

    File.open(@output, 'w') {|f| f.write(t) }

    puts "Created #{output}, v#{major}.#{minor}.#{patch} [#{revision[0..10]}]"
  end
end