Class: VersionInfo::TextStorage
- Inherits:
-
Storage
- Object
- Storage
- VersionInfo::TextStorage
show all
- Defined in:
- lib/version_info/text_storage.rb
Overview
Version data is stored in a text file with this structure 2.2.3 # => numeric segments at first line author: jcangas # => custom key after, one per line email: [email protected] # => another custom key
The convenion is to name this file “VERSION”
Instance Attribute Summary
Attributes inherited from Storage
#data
Instance Method Summary
collapse
Methods inherited from Storage
#file_name, #file_name=, #initialize, #save
Instance Method Details
#default_file_name ⇒ Object
12
13
14
|
# File 'lib/version_info/text_storage.rb', line 12
def default_file_name
'VERSION'
end
|
#load ⇒ Object
20
21
22
23
24
|
# File 'lib/version_info/text_storage.rb', line 20
def load
content = load_content
parse_from(content)
self
end
|
#load_content ⇒ Object
16
17
18
|
# File 'lib/version_info/text_storage.rb', line 16
def load_content
File.exist?(file_name) ? File.readlines(file_name) : [""]
end
|
#parse_from(content) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/version_info/text_storage.rb', line 26
def parse_from(content)
str = content.shift
custom = content.inject({}) {|result, line| k, v = line.chomp.split(':'); result[k.strip.to_sym] = v.strip; result}
data.set_version_info(str)
data.to_hash.merge!(custom)
self
end
|
#save_to(io) ⇒ Object
34
35
36
37
38
|
# File 'lib/version_info/text_storage.rb', line 34
def save_to(io)
io.puts data.tag data.to_hash.each {|k, v| io.puts "#{k}: #{v}" unless data.segments.include?(k) }
self
end
|