Class: Ritual::VersionFile
- Inherits:
-
Object
- Object
- Ritual::VersionFile
- Defined in:
- lib/ritual/version_file.rb
Constant Summary collapse
- VERSION_REGEXP =
/^\s*VERSION\s*=\s*(\[.*?\])/
Instance Attribute Summary collapse
-
#library_name ⇒ Object
readonly
Returns the value of attribute library_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #increment(component) ⇒ Object
-
#initialize(path, library_name) ⇒ VersionFile
constructor
A new instance of VersionFile.
- #to_s ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(path, library_name) ⇒ VersionFile
Returns a new instance of VersionFile.
5 6 7 8 9 |
# File 'lib/ritual/version_file.rb', line 5 def initialize(path, library_name) @path = path @library_name = library_name @value ||= read end |
Instance Attribute Details
#library_name ⇒ Object (readonly)
Returns the value of attribute library_name.
11 12 13 |
# File 'lib/ritual/version_file.rb', line 11 def library_name @library_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/ritual/version_file.rb', line 11 def path @path end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'lib/ritual/version_file.rb', line 11 def value @value end |
Instance Method Details
#increment(component) ⇒ Object
43 44 45 46 47 |
# File 'lib/ritual/version_file.rb', line 43 def increment(component) (value.size..component).each{|i| value[i] = 0} value[component] += 1 (component+1 ... value.size).each{|i| value[i] = 0} end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/ritual/version_file.rb', line 13 def to_s value.join('.') end |
#write ⇒ Object
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 |
# File 'lib/ritual/version_file.rb', line 17 def write if File.exist?(path) source = File.read(path).sub(VERSION_REGEXP) do |s| "#{s[/\s*/]}VERSION = [#{@value.join(', ')}]" end open(path, 'w') { |f| f.puts source} else FileUtils.mkdir_p File.dirname(path) open(path, 'w') do |file| file.puts <<-EOS.gsub(/^ *\|/, '') |module #{module_name} | VERSION = #{value.inspect} | | class << VERSION | include Comparable | | def to_s | join('.') | end | end |end EOS end end end |