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.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Class Method Summary collapse
Instance Method Summary collapse
-
#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, process) ⇒ 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, process) ⇒ Node
Returns a new instance of Node.
28 29 30 31 32 33 34 35 |
# File 'lib/build/graph/node.rb', line 28 def initialize(inputs, outputs, process) # These are immutable - rather than change them, create a new node: @inputs = inputs @outputs = outputs # Represents an abstract process, e.g. a name or a function. @process = process end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
37 38 39 |
# File 'lib/build/graph/node.rb', line 37 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
38 39 40 |
# File 'lib/build/graph/node.rb', line 38 def outputs @outputs end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
39 40 41 |
# File 'lib/build/graph/node.rb', line 39 def process @process end |
Class Method Details
.top(inputs = Files::Paths::NONE, outputs = :inherit, **options, &block) ⇒ Object
93 94 95 |
# File 'lib/build/graph/node.rb', line 93 def self.top(inputs = Files::Paths::NONE, outputs = :inherit, **, &block) self.new(inputs, outputs, block, **) end |
Instance Method Details
#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.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/build/graph/node.rb', line 56 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
81 82 83 |
# File 'lib/build/graph/node.rb', line 81 def eql?(other) other.kind_of?(self.class) and @inputs.eql?(other.inputs) and @outputs.eql?(other.outputs) and @process.eql?(other.process) end |
#hash ⇒ Object
85 86 87 |
# File 'lib/build/graph/node.rb', line 85 def hash [@inputs, @outputs, @process].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.
42 43 44 |
# File 'lib/build/graph/node.rb', line 42 def inherit_outputs? @outputs == :inherit end |
#inspect ⇒ Object
89 90 91 |
# File 'lib/build/graph/node.rb', line 89 def inspect "#<#{self.class} #{@inputs.inspect} => #{@outputs.inspect} by #{@process}>" end |
#missing? ⇒ Boolean
51 52 53 |
# File 'lib/build/graph/node.rb', line 51 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.
47 48 49 |
# File 'lib/build/graph/node.rb', line 47 def modified_time @inputs.map{|path| path.modified_time}.max end |