Class: Build::Graph::Node
- Inherits:
-
Object
- Object
- Build::Graph::Node
- Defined in:
- lib/build/graph/node.rb
Overview
This is essentialy a immutable key:
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#dirty? ⇒ Boolean
This is a canonical dirty function.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#inherit_outputs? ⇒ Boolean
Nodes that inherit outputs are special in the sense that outputs are not available until all child nodes have been evaluated.
-
#initialize(inputs, outputs) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
- #missing? ⇒ Boolean
-
#modified_time ⇒ Object
This computes the most recent modified time for all inputs.
Constructor Details
#initialize(inputs, outputs) ⇒ Node
Returns a new instance of Node.
29 30 31 32 |
# File 'lib/build/graph/node.rb', line 29 def initialize(inputs, outputs) @inputs = inputs @outputs = outputs end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
34 35 36 |
# File 'lib/build/graph/node.rb', line 34 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
35 36 37 |
# File 'lib/build/graph/node.rb', line 35 def outputs @outputs end |
Class Method Details
.top(inputs = Files::Paths::NONE, outputs = :inherit, **options, &block) ⇒ Object
96 97 98 |
# File 'lib/build/graph/node.rb', line 96 def self.top(inputs = Files::Paths::NONE, outputs = :inherit, **, &block) self.new(inputs, outputs, block, **) end |
Instance Method Details
#==(other) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/build/graph/node.rb', line 77 def == other self.equal?(other) or self.class == other.class and @inputs == other.inputs and @outputs == other.outputs end |
#dirty? ⇒ Boolean
This is a canonical dirty function. All outputs must exist and must be newer than all inputs. This function is not efficient, in the sense that it must query all files on disk for last modified time.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/build/graph/node.rb', line 52 def dirty? if inherit_outputs? return true elsif @inputs.count == 0 or @outputs.count == 0 # If there are no inputs or no outputs we are always dirty: return true # I'm not entirely sure this is the correct approach. If input is a glob that matched zero items, but might match items that are older than outputs, what is the correct output from this function? else # Dirty if any inputs or outputs missing: return true if missing? # Dirty if input modified after any output: if input_modified_time = self.modified_time # Outputs should always be more recent than their inputs: return true if @outputs.any?{|output_path| output_path.modified_time < input_modified_time} else # None of the inputs exist: true end end return false end |
#eql?(other) ⇒ Boolean
84 85 86 |
# File 'lib/build/graph/node.rb', line 84 def eql?(other) self.equal?(other) or self == other end |
#hash ⇒ Object
88 89 90 |
# File 'lib/build/graph/node.rb', line 88 def hash @inputs.hash ^ @outputs.hash end |
#inherit_outputs? ⇒ Boolean
Nodes that inherit outputs are special in the sense that outputs are not available until all child nodes have been evaluated.
38 39 40 |
# File 'lib/build/graph/node.rb', line 38 def inherit_outputs? @outputs == :inherit end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/build/graph/node.rb', line 92 def inspect "#<#{self.class} #{@inputs.inspect} => #{@outputs.inspect}>" end |
#missing? ⇒ Boolean
47 48 49 |
# File 'lib/build/graph/node.rb', line 47 def missing? @outputs.any?{|path| !path.exist?} || @inputs.any?{|path| !path.exist?} end |
#modified_time ⇒ Object
This computes the most recent modified time for all inputs.
43 44 45 |
# File 'lib/build/graph/node.rb', line 43 def modified_time @inputs.map{|path| path.modified_time}.max end |