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 Attribute Summary

Attributes inherited from Storage

#data

Instance Method Summary collapse

Methods inherited from Storage

#file_name, #file_name=, #initialize

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

#loadObject



23
24
25
26
27
# File 'lib/version_info/module_storage.rb', line 23

def load
  content = load_content
  parse_from(content)
  self
end

#load_contentObject



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

def load_content
  File.readlines(file_name)
end

#parse_from(content) ⇒ Object



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

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

#saveObject



36
37
38
39
40
41
42
# File 'lib/version_info/module_storage.rb', line 36

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