Sha256: e592be505cb33b8fccd5936e7c04e3c2ad5c9acf458e136bebdaac12403a482f

Contents?: true

Size: 953 Bytes

Versions: 2

Compression:

Stored size: 953 Bytes

Contents

# frozen_string_literal: true

# 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: Returns true if watched files have changed since the last build.
  def stale?
    digest != current_digest
  end

  # Internal: Returns true if watched files have not changed since the last build.
  def fresh?
    !stale?
  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

2 entries across 2 versions & 1 rubygems

Version Path
vite_ruby-1.1.1 lib/vite_ruby/build.rb
vite_ruby-1.1.0 lib/vite_ruby/build.rb