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
-
#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.
30 31 32 33 34 35 36 37 |
# File 'lib/build/graph/node.rb', line 30 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.
39 40 41 |
# File 'lib/build/graph/node.rb', line 39 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
40 41 42 |
# File 'lib/build/graph/node.rb', line 40 def outputs @outputs end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
41 42 43 |
# File 'lib/build/graph/node.rb', line 41 def process @process end |
Class Method Details
.top(inputs = Files::Paths::NONE, outputs = :inherit, **options, &block) ⇒ Object
91 92 93 |
# File 'lib/build/graph/node.rb', line 91 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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/build/graph/node.rb', line 54 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 outputs don't exist: return true if @outputs.any?{|path| !path.exist?} # 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
79 80 81 |
# File 'lib/build/graph/node.rb', line 79 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
83 84 85 |
# File 'lib/build/graph/node.rb', line 83 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.
44 45 46 |
# File 'lib/build/graph/node.rb', line 44 def inherit_outputs? @outputs == :inherit end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/build/graph/node.rb', line 87 def inspect "<#{self.class.name} #{@inputs.inspect} => #{@outputs.inspect} by #{@process.inspect}>" end |
#modified_time ⇒ Object
This computes the most recent modified time for all inputs.
49 50 51 |
# File 'lib/build/graph/node.rb', line 49 def modified_time modified_time = @inputs.map{|path| path.modified_time}.max end |