Class: Build::Files::State
- Inherits:
-
Object
- Object
- Build::Files::State
- Defined in:
- lib/build/files/state.rb
Instance Attribute Summary collapse
-
#added ⇒ Object
readonly
Returns the value of attribute added.
-
#changed ⇒ Object
readonly
Returns the value of attribute changed.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#missing ⇒ Object
readonly
Returns the value of attribute missing.
-
#newest_time ⇒ Object
readonly
Returns the value of attribute newest_time.
-
#oldest_time ⇒ Object
readonly
Returns the value of attribute oldest_time.
-
#removed ⇒ Object
readonly
Returns the value of attribute removed.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(files) ⇒ State
constructor
A new instance of State.
- #inspect ⇒ Object
-
#intersects?(outputs) ⇒ Boolean
Outputs is a list of full paths and must not include any patterns/globs.
- #missing? ⇒ Boolean
- #update! ⇒ Object
Constructor Details
Instance Attribute Details
#added ⇒ Object (readonly)
Returns the value of attribute added.
57 58 59 |
# File 'lib/build/files/state.rb', line 57 def added @added end |
#changed ⇒ Object (readonly)
Returns the value of attribute changed.
59 60 61 |
# File 'lib/build/files/state.rb', line 59 def changed @changed end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
55 56 57 |
# File 'lib/build/files/state.rb', line 55 def files @files end |
#missing ⇒ Object (readonly)
Returns the value of attribute missing.
60 61 62 |
# File 'lib/build/files/state.rb', line 60 def missing @missing end |
#newest_time ⇒ Object (readonly)
Returns the value of attribute newest_time.
114 115 116 |
# File 'lib/build/files/state.rb', line 114 def newest_time @newest_time end |
#oldest_time ⇒ Object (readonly)
Returns the value of attribute oldest_time.
113 114 115 |
# File 'lib/build/files/state.rb', line 113 def oldest_time @oldest_time end |
#removed ⇒ Object (readonly)
Returns the value of attribute removed.
58 59 60 |
# File 'lib/build/files/state.rb', line 58 def removed @removed end |
#times ⇒ Object (readonly)
Returns the value of attribute times.
62 63 64 |
# File 'lib/build/files/state.rb', line 62 def times @times end |
Instance Method Details
#empty? ⇒ Boolean
127 128 129 |
# File 'lib/build/files/state.rb', line 127 def empty? @files.to_a.empty? end |
#inspect ⇒ Object
131 132 133 |
# File 'lib/build/files/state.rb', line 131 def inspect "<State Added:#{@added} Removed:#{@removed} Changed:#{@changed} Missing:#{@missing}>" end |
#intersects?(outputs) ⇒ Boolean
Outputs is a list of full paths and must not include any patterns/globs.
123 124 125 |
# File 'lib/build/files/state.rb', line 123 def intersects?(outputs) @files.intersects?(outputs) end |
#missing? ⇒ Boolean
118 119 120 |
# File 'lib/build/files/state.rb', line 118 def missing? !@missing.empty? end |
#update! ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/build/files/state.rb', line 64 def update! last_times = @times @times = {} @added = [] @removed = [] @changed = [] @missing = [] file_times = [] @files.each do |path| # When processing the same path twice (perhaps by accident), we should skip it otherwise it might cause issues when being deleted from last_times multuple times. next if @times.include? path if File.exist?(path) modified_time = File.mtime(path) if last_time = last_times.delete(path) # Path was valid last update: if modified_time != last_time @changed << path # puts "Changed: #{path}" end else # Path didn't exist before: @added << path # puts "Added: #{path}" end @times[path] = modified_time unless File.directory?(path) file_times << FileTime.new(path, modified_time) end else @missing << path # puts "Missing: #{path}" end end @removed = last_times.keys @oldest_time = file_times.min @newest_time = file_times.max return @added.size > 0 || @changed.size > 0 || @removed.size > 0 || @missing.size > 0 end |