Class: Teapot::Graph::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/teapot/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, path) ⇒ Node

Returns a new instance of Node.



76
77
78
79
80
81
82
83
84
# File 'lib/teapot/graph.rb', line 76

def initialize(graph, path)
  @graph = graph

  @path = Pathname(path)

  @dependencies = []

  @changed = nil
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



87
88
89
# File 'lib/teapot/graph.rb', line 87

def dependencies
  @dependencies
end

#pathObject (readonly)

Returns the value of attribute path.



86
87
88
# File 'lib/teapot/graph.rb', line 86

def path
  @path
end

Instance Method Details

#changed_since?(modified_time) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/teapot/graph.rb', line 89

def changed_since?(modified_time)
  if @changed == nil
    # If the file was modified in the future relative to old modified_time:
    if @path.mtime > modified_time
      puts "Changed: #{path.to_s.inspect}"
      return @changed = true
    else
      @changed = false
    end

    # If any of the file's dependencies have changed relative to the old modified_time:
    @dependencies.each do |dependency|
      if dependency.changed_since?(modified_time)
        return @changed = true
      end
    end
  end

  return @changed
end

#extract_dependencies!Object



110
111
112
# File 'lib/teapot/graph.rb', line 110

def extract_dependencies!
  @dependencies = @graph.extract(path)
end