class ReleaseNumber
  attr_reader :release

  def initialize(release)
    @release = release
  end

  def value
    (release_ids.index(release.id) || 0) + 1
  end

  private

  def project
    release.project
  end

  def release_ids
    project.public_send(release_type).order(Arel.sql("COALESCE(signed_at, created_at) ASC")).ids
  end

  def release_type
    release.model_name.plural
  end
end
