module CommitMetadataPersistable

Provides methods relating to persisting commit metadata

Attributes

commit[RW]

Private Instance Methods

filename() click to toggle source
# File lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb, line 42
def filename
  "rake_ci.#{name}.yml"
end
load_current_commit_data() click to toggle source
# File lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb, line 20
def load_current_commit_data
  load_hash_matching(commit.oid)[:payload]
end
load_hash_matching(*commits) click to toggle source
# File lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb, line 24
def load_hash_matching(*commits)
  match = Array.wrap(YAML.load_file(filename)).
          detect { |h| commits.include? h[:commit] }

  match || {}
rescue Errno::ENOENT
  {}
end
load_last_commit_data() click to toggle source
# File lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb, line 16
def load_last_commit_data
  load_hash_matching(*commit.parents.map(&:oid))[:payload]
end
name() click to toggle source
# File lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb, line 46
def name
  self.class.name.demodulize.underscore.sub(/_helper\z/, '')
end
save_current_commit_data(data) click to toggle source
# File lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb, line 33
def save_current_commit_data(data)
  hashes = [
    load_hash_matching(*commit.parents.map(&:oid)),
    { commit: commit.oid, payload: data }
  ].reject(&:blank?)

  File.write(filename, YAML.dump(hashes))
end