Class: ViteRuby::Build
- Inherits:
-
Struct
- Object
- Struct
- ViteRuby::Build
- Defined in:
- lib/vite_ruby/build.rb
Overview
Internal: Value object with information about the last build.
Instance Attribute Summary collapse
-
#current_digest ⇒ Object
Returns the value of attribute current_digest.
-
#digest ⇒ Object
Returns the value of attribute digest.
-
#success ⇒ Object
Returns the value of attribute success.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#vite_ruby ⇒ Object
Returns the value of attribute vite_ruby.
Class Method Summary collapse
-
.from_previous(attrs, current_digest) ⇒ Object
Internal: Combines information from a previous build with the current digest.
Instance Method Summary collapse
-
#fresh? ⇒ Boolean
Internal: A build is considered fresh if watched files have not changed, or the last failed build happened recently.
-
#retry_failed? ⇒ Boolean
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.
-
#stale? ⇒ Boolean
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.
-
#to_json(*_args) ⇒ Object
Internal: Returns a JSON string with the metadata of the build.
-
#with_result(success) ⇒ Object
Internal: Returns a new build with the specified result.
Instance Attribute Details
#current_digest ⇒ Object
Returns the value of attribute current_digest
6 7 8 |
# File 'lib/vite_ruby/build.rb', line 6 def current_digest @current_digest end |
#digest ⇒ Object
Returns the value of attribute digest
6 7 8 |
# File 'lib/vite_ruby/build.rb', line 6 def digest @digest end |
#success ⇒ Object
Returns the value of attribute success
6 7 8 |
# File 'lib/vite_ruby/build.rb', line 6 def success @success end |
#timestamp ⇒ Object
Returns the value of attribute timestamp
6 7 8 |
# File 'lib/vite_ruby/build.rb', line 6 def end |
#vite_ruby ⇒ Object
Returns the value of attribute vite_ruby
6 7 8 |
# File 'lib/vite_ruby/build.rb', line 6 def vite_ruby @vite_ruby end |
Class Method Details
.from_previous(attrs, current_digest) ⇒ Object
Internal: Combines information from a previous build with the current digest.
8 9 10 11 12 13 14 15 16 |
# File 'lib/vite_ruby/build.rb', line 8 def self.from_previous(attrs, current_digest) new( attrs['success'], attrs['timestamp'] || 'never', attrs['vite_ruby'] || 'unknown', attrs['digest'] || 'none', current_digest, ) end |
Instance Method Details
#fresh? ⇒ Boolean
Internal: A build is considered fresh if watched files have not changed, or the last failed build happened recently.
26 27 28 |
# File 'lib/vite_ruby/build.rb', line 26 def fresh? !stale? end |
#retry_failed? ⇒ Boolean
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.
32 33 34 35 36 |
# File 'lib/vite_ruby/build.rb', line 32 def retry_failed? !success && Time.parse() + 3 < Time.now # 3 seconds rescue ArgumentError true end |
#stale? ⇒ Boolean
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.
20 21 22 |
# File 'lib/vite_ruby/build.rb', line 20 def stale? digest != current_digest || retry_failed? || vite_ruby != ViteRuby::VERSION end |
#to_json(*_args) ⇒ Object
Internal: Returns a JSON string with the metadata of the build.
49 50 51 |
# File 'lib/vite_ruby/build.rb', line 49 def to_json(*_args) JSON.pretty_generate(to_h) end |
#with_result(success) ⇒ Object
Internal: Returns a new build with the specified result.
39 40 41 42 43 44 45 46 |
# File 'lib/vite_ruby/build.rb', line 39 def with_result(success) self.class.new( success, Time.now.strftime('%F %T'), ViteRuby::VERSION, current_digest, ) end |