Class: VersionInfo::TextStorage
- 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
Instance Method Summary collapse
- #default_file_name ⇒ Object
- #load_content(io) ⇒ Object
- #load_from(io) ⇒ Object
- #save_to(io) ⇒ Object
Methods inherited from Storage
#file_name, #file_name=, #initialize, #load, #save
Constructor Details
This class inherits a constructor from VersionInfo::Storage
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_content(io) ⇒ Object
16 17 18 |
# File 'lib/version_info/text_storage.rb', line 16 def load_content(io) io.readlines end |
#load_from(io) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/version_info/text_storage.rb', line 20 def load_from(io) content = load_content(io) 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
29 30 31 32 33 |
# File 'lib/version_info/text_storage.rb', line 29 def save_to(io) io.puts data.tag #VersionInfo.segments.map{|sgm| data.send(sgm)}.join('.') data.to_hash.each {|k, v| io.puts "#{k}: #{v}" unless data.segments.include?(k) } self end |