Sha256: 7a142725d5e84ea570a2147ab24bc1434effdd1743c33d8f4d0cd0e57f8fb2ba

Contents?: true

Size: 1.02 KB

Versions: 48

Compression:

Stored size: 1.02 KB

Contents

require 'active_support/concern'
require 'active_support/core_ext/array/wrap'
require 'active_support/inflector'
require 'yaml'

# Provides methods relating to persisting commit metadata
module CommitMetadataPersistable
  extend ActiveSupport::Concern

  included do
    attr_accessor :commit
  end

  private

  def load_last_commit_data
    load_hash_matching(*commit.parents.map(&:oid))[:payload]
  end

  def load_current_commit_data
    load_hash_matching(commit.oid)[:payload]
  end

  def load_hash_matching(*commits)
    match = Array.wrap(YAML.load_file(filename)).
            detect { |h| commits.include? h[:commit] }

    match || {}
  rescue Errno::ENOENT
    {}
  end

  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

  def filename
    "rake_ci.#{name}.yml"
  end

  def name
    self.class.name.demodulize.underscore.sub(/_helper\z/, '')
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
ndr_dev_support-7.3.1 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.3.0 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.6 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.5 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.4 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.3 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.2 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.1 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.2.0 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.1.0 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-7.0.0 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.9 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.8 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.7 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.6 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.5 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.4 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.3 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.2 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb
ndr_dev_support-6.1.1 lib/ndr_dev_support/rake_ci/concerns/commit_metadata_persistable.rb