Sha256: 961a973ed2f2c908efc261043af8b3275a0f6568d5fa651dedb25e11c84cfb9a

Contents?: true

Size: 1.36 KB

Versions: 28

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'time'

# Internal: Value object with information about the last build.
ViteRuby::Build = Struct.new(:success, :timestamp, :digest, :current_digest) do
  # Internal: Combines information from a previous build with the current digest.
  def self.from_previous(attrs, current_digest)
    new(attrs['success'], attrs['timestamp'] || 'never', attrs['digest'] || 'none', current_digest)
  end

  # Internal: A build is considered stale when watched files have changed since
  # the last build, or when a certain time has ellapsed in case of failure.
  def stale?
    digest != current_digest || retry_failed?
  end

  # Internal: A build is considered fresh if watched files have not changed, or
  # the last failed build happened recently.
  def fresh?
    !stale?
  end

  # Internal: To avoid cascading build failures, if the last build failed and it
  # happened within a short time window, a new build should not be triggered.
  def retry_failed?
    !success && Time.parse(timestamp) + 3 < Time.now # 3 seconds
  rescue ArgumentError
    true
  end

  # Internal: Returns a new build with the specified result.
  def with_result(success)
    self.class.new(success, Time.now.strftime('%F %T'), current_digest)
  end

  # Internal: Returns a JSON string with the metadata of the build.
  def to_json(*_args)
    JSON.pretty_generate(to_h)
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
vite_ruby-2.0.0.beta.6 lib/vite_ruby/build.rb
vite_ruby-2.0.0.beta.5 lib/vite_ruby/build.rb
vite_ruby-2.0.0.beta.4 lib/vite_ruby/build.rb
vite_ruby-2.0.0.beta.3 lib/vite_ruby/build.rb
vite_ruby-2.0.0.beta.2 lib/vite_ruby/build.rb
vite_ruby-2.0.0.beta.1 lib/vite_ruby/build.rb
vite_ruby-1.2.20 lib/vite_ruby/build.rb
vite_ruby-1.2.18 lib/vite_ruby/build.rb
vite_ruby-1.2.18.pre.rc1 lib/vite_ruby/build.rb
vite_ruby-1.2.17 lib/vite_ruby/build.rb
vite_ruby-1.2.16 lib/vite_ruby/build.rb
vite_ruby-1.2.15 lib/vite_ruby/build.rb
vite_ruby-1.2.14 lib/vite_ruby/build.rb
vite_ruby-1.2.13 lib/vite_ruby/build.rb
vite_ruby-1.2.12 lib/vite_ruby/build.rb
vite_ruby-1.2.11 lib/vite_ruby/build.rb
vite_ruby-1.2.10 lib/vite_ruby/build.rb
vite_ruby-1.2.9 lib/vite_ruby/build.rb
vite_ruby-1.2.8 lib/vite_ruby/build.rb
vite_ruby-1.2.7 lib/vite_ruby/build.rb