Class: DevopsHelper::VersionStore
- Inherits:
-
Object
- Object
- DevopsHelper::VersionStore
- Defined in:
- lib/devops_helper/version_store.rb
Constant Summary collapse
- VERSTORE_NAME =
".version_history.yml"
Instance Attribute Summary collapse
-
#history ⇒ Object
Returns the value of attribute history.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(history = { }, opts = { }) ⇒ VersionStore
constructor
A new instance of VersionStore.
-
#last_version(gname) ⇒ Object
register_version.
- #register_version(gname, version) ⇒ Object
- #save(root = @root) ⇒ Object
Constructor Details
#initialize(history = { }, opts = { }) ⇒ VersionStore
Returns a new instance of VersionStore.
13 14 15 16 17 |
# File 'lib/devops_helper/version_store.rb', line 13 def initialize(history = { }, opts = { }) @history = history @root = opts[:root] @logger = opts[:logger] || Global.instance.logger end |
Instance Attribute Details
#history ⇒ Object
Returns the value of attribute history.
11 12 13 |
# File 'lib/devops_helper/version_store.rb', line 11 def history @history end |
Class Method Details
.load(root) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/devops_helper/version_store.rb', line 49 def self.load(root) path = File.join(root,VERSTORE_NAME) if File.exist?(path) hist = YAML.load(File.read(path)) VersionStore.new(hist, { root: root }) else VersionStore.new end end |
Instance Method Details
#last_version(gname) ⇒ Object
register_version
33 34 35 36 37 38 39 40 |
# File 'lib/devops_helper/version_store.rb', line 33 def last_version(gname) if not_empty?(gname) rec = @history[gname.strip] rec.last if not_empty?(rec) else raise DevopsHelper::Error, "Gem name is empty" end end |
#register_version(gname, version) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/devops_helper/version_store.rb', line 19 def register_version(gname, version) raise DevopsHelper::Error, "Gem name cannot be empty" if is_empty?(gname) raise DevopsHelper::Error, "Version cannot be empty" if is_empty?(version) # todo validate version is in form 'x.y.z' and not 'vx.y.z' or 'version x.y.z' nm = gname.strip @history[nm] = [] if not @history.keys.include?(nm) verInfo = { } verInfo[:version] = version verInfo[:created_at] = Time.now @history[nm] << verInfo @history[nm] end |
#save(root = @root) ⇒ Object
43 44 45 46 47 |
# File 'lib/devops_helper/version_store.rb', line 43 def save(root = @root) File.open(File.join(root,VERSTORE_NAME),"w") do |f| f.write YAML.dump(@history) end end |