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
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_from(io) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/version_info/text_storage.rb', line 16 def load_from(io) #content = io.string.split("\n") unless io.is_a? Array content = io.readlines 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
26 27 28 29 30 |
# File 'lib/version_info/text_storage.rb', line 26 def save_to(io) io.puts VersionInfo.segments.map{|sgm| data.send(sgm)}.join('.') data.to_hash.each {|k, v| io.puts "#{k}: #{v}" unless VersionInfo.segments.include?(k) } self end |