Class: VersionInfo::ModuleStorage

Inherits:
Storage
  • Object
show all
Defined in:
lib/version_info/module_storage.rb

Overview

module MyProject

VERSION = "0.0.1"
VERSION.author = "jcangas"
VERSION.email = "[email protected]"

end

The convenion is to name this file “version.rb”

Instance Method Summary collapse

Methods inherited from Storage

#data, #file_name, #initialize, #load, #load_content

Constructor Details

This class inherits a constructor from VersionInfo::Storage

Instance Method Details

#default_file_nameObject



15
16
17
# File 'lib/version_info/module_storage.rb', line 15

def default_file_name
  'version.rb'
end

#parse_from(content) ⇒ Object



19
20
21
22
23
24
# File 'lib/version_info/module_storage.rb', line 19

def parse_from(content)
  match = content.join.match /(\s*VERSION\s*=\s*)('|")(.*)('|")/
  str = match ? match[3] : "0.0.0"
  data.set_version_info(str)
  self
end

#saveObject



26
27
28
29
30
31
32
33
# File 'lib/version_info/module_storage.rb', line 26

def save      
  content = load_content.join
  content = "VERSION = '#{data.tag}'" if content.empty?
  content.gsub!(/(\s*VERSION\s*=\s*)('|").*('|")/, "\\1\\2#{data.tag}\\3")
 File.open(file_name, 'w' ) {|out| out.print content}
 self
  content
end