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.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#last_build_path ⇒ Object
Returns the value of attribute last_build_path.
-
#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(last_build_path, 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(**attrs) ⇒ Object
Internal: Returns a new build with the specified result.
-
#write_to_cache ⇒ Object
Internal: Writes the result of the new build to a local file.
Instance Attribute Details
#current_digest ⇒ Object
Returns the value of attribute current_digest
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def current_digest @current_digest end |
#digest ⇒ Object
Returns the value of attribute digest
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def digest @digest end |
#errors ⇒ Object
Returns the value of attribute errors
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def errors @errors end |
#last_build_path ⇒ Object
Returns the value of attribute last_build_path
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def last_build_path @last_build_path end |
#success ⇒ Object
Returns the value of attribute success
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def success @success end |
#timestamp ⇒ Object
Returns the value of attribute timestamp
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def @timestamp end |
#vite_ruby ⇒ Object
Returns the value of attribute vite_ruby
7 8 9 |
# File 'lib/vite_ruby/build.rb', line 7 def vite_ruby @vite_ruby end |
Class Method Details
.from_previous(last_build_path, current_digest) ⇒ Object
Internal: Combines information from a previous build with the current digest.
10 11 12 13 14 15 16 |
# File 'lib/vite_ruby/build.rb', line 10 def from_previous(last_build_path, current_digest) new( **(last_build_path), current_digest: current_digest, last_build_path: last_build_path, ) 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.
43 44 45 |
# File 'lib/vite_ruby/build.rb', line 43 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.
49 50 51 52 53 |
# File 'lib/vite_ruby/build.rb', line 49 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.
37 38 39 |
# File 'lib/vite_ruby/build.rb', line 37 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.
73 74 75 76 77 78 79 80 81 |
# File 'lib/vite_ruby/build.rb', line 73 def to_json(*_args) JSON.pretty_generate( success: success, errors: errors, timestamp: , vite_ruby: vite_ruby, digest: digest, ) end |
#with_result(**attrs) ⇒ Object
Internal: Returns a new build with the specified result.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vite_ruby/build.rb', line 56 def with_result(**attrs) self.class.new( **attrs, timestamp: Time.now.strftime("%F %T"), vite_ruby: ViteRuby::VERSION, digest: current_digest, current_digest: current_digest, last_build_path: last_build_path, ) end |
#write_to_cache ⇒ Object
Internal: Writes the result of the new build to a local file.
68 69 70 |
# File 'lib/vite_ruby/build.rb', line 68 def write_to_cache last_build_path.write to_json end |