Sha256: f172c5337fc1dfb669c24cf38d005a8bfcca214ec44d1f3d061b8c34f6fd9e6f

Contents?: true

Size: 621 Bytes

Versions: 9

Compression:

Stored size: 621 Bytes

Contents

module BelongsToCommit
  extend ActiveSupport::Concern

  included do
    belongs_to :commit
    before_validation :identify_commit, on: :create
    validates :sha, presence: {message: "must refer to a commit"}
  end

private

  def identify_commit
    return unless project && sha
    self.commit = project.find_commit_by_sha(sha)
    self.sha = commit.sha if commit
  rescue Houston::Adapters::VersionControl::InvalidShaError
    Rails.logger.warn "\e[31m[#{self.class.name.underscore}] Unable to identify commit\e[0m"
    Rails.logger.warn "#{$!.class}: #{$!.message}\n#{$!.backtrace.join("\n  ")}"
    nil
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
houston-core-0.6.0 app/concerns/belongs_to_commit.rb
houston-core-0.5.6 app/concerns/belongs_to_commit.rb
houston-core-0.5.5 app/concerns/belongs_to_commit.rb
houston-core-0.5.4 app/concerns/belongs_to_commit.rb
houston-core-0.5.3 app/concerns/belongs_to_commit.rb
houston-core-0.5.2 app/concerns/belongs_to_commit.rb
houston-core-0.5.1 app/concerns/belongs_to_commit.rb
houston-core-0.5.0 app/concerns/belongs_to_commit.rb
houston-core-0.5.0.beta1 app/concerns/belongs_to_commit.rb