Class: VersionInfo::Data
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- VersionInfo::Data
- Defined in:
- lib/version_info/data.rb
Instance Method Summary collapse
- #assign(hash) ⇒ Object
- #bump(key) ⇒ Object
- #file_name ⇒ Object
- #file_name=(value) ⇒ Object
- #get_defaults ⇒ Object
-
#initialize ⇒ Data
constructor
A new instance of Data.
- #load ⇒ Object
- #reset ⇒ Object
- #save ⇒ Object
- #set_version_info(tag_str) ⇒ Object
- #storage ⇒ Object
- #tag ⇒ Object
- #tag_format ⇒ Object
- #tag_format=(value) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Data
6 7 8 9 |
# File 'lib/version_info/data.rb', line 6 def initialize super reset end |
Instance Method Details
#assign(hash) ⇒ Object
38 39 40 |
# File 'lib/version_info/data.rb', line 38 def assign(hash) marshal_load(hash) end |
#bump(key) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/version_info/data.rb', line 42 def bump(key) idx = VersionInfo.segments.index(key.to_sym) + 1 return unless idx VersionInfo.segments[idx..-1].each do |sgm| send("#{sgm}=", 0) if send(sgm) end send("#{key}=", 1 + send(key).to_i) end |
#file_name ⇒ Object
15 16 17 |
# File 'lib/version_info/data.rb', line 15 def file_name storage.file_name end |
#file_name=(value) ⇒ Object
19 20 21 22 |
# File 'lib/version_info/data.rb', line 19 def file_name=(value) @storage = nil #recreate storage storage.file_name = value end |
#get_defaults ⇒ Object
76 77 78 |
# File 'lib/version_info/data.rb', line 76 def get_defaults VersionInfo.segments[0..2].inject({}){|h, k| h[k] = 0; h} end |
#load ⇒ Object
24 25 26 27 |
# File 'lib/version_info/data.rb', line 24 def load storage.load self end |
#reset ⇒ Object
34 35 36 |
# File 'lib/version_info/data.rb', line 34 def reset assign(get_defaults) end |
#save ⇒ Object
29 30 31 32 |
# File 'lib/version_info/data.rb', line 29 def save storage.save self end |
#set_version_info(tag_str) ⇒ Object
71 72 73 74 |
# File 'lib/version_info/data.rb', line 71 def set_version_info(tag_str) values = tag_str.to_s.split('.') VersionInfo.segments.each{|sgm| self.send("#{sgm}=", values.shift.match(/(\d+)/).to_s.to_i) } end |
#storage ⇒ Object
11 12 13 |
# File 'lib/version_info/data.rb', line 11 def storage @storage ||= STORAGE_CLASS[VersionInfo.file_format.to_sym].new(self) end |
#tag ⇒ Object
59 60 61 |
# File 'lib/version_info/data.rb', line 59 def tag tag_format % to_hash end |
#tag_format ⇒ Object
63 64 65 |
# File 'lib/version_info/data.rb', line 63 def tag_format @tag_format ||= VersionInfo.segments.map { |k| "%<#{k}>d"}.join('.') end |
#tag_format=(value) ⇒ Object
67 68 69 |
# File 'lib/version_info/data.rb', line 67 def tag_format=(value) @tag_format = value end |
#to_hash ⇒ Object
55 56 57 |
# File 'lib/version_info/data.rb', line 55 def to_hash marshal_dump end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/version_info/data.rb', line 51 def to_s tag end |