Class: DeltaTest::DependenciesTable
- Inherits:
-
Hash
- Object
- Hash
- DeltaTest::DependenciesTable
- Defined in:
- lib/delta_test/dependencies_table.rb
Constant Summary collapse
- DEFAULT_PROC =
-> (h, k) { h[k] = ::Set.new }
Class Method Summary collapse
-
.load(file) ⇒ Object
Restore a table object from a file.
Instance Method Summary collapse
-
#add(spec_file, source_file) ⇒ Object
Add a dependency for a spec file.
-
#cleanup! ⇒ Object
Cleanup empty sets from the table.
-
#dump(file) ⇒ Object
Dump the table object to a file.
-
#initialize ⇒ DependenciesTable
constructor
A new instance of DependenciesTable.
-
#reverse_merge!(other) ⇒ Object
Reverse merge other table.
-
#without_default_proc ⇒ Object
Temporary disable default_proc Because Marshal can’t dump Hash with default_proc.
Constructor Details
#initialize ⇒ DependenciesTable
Returns a new instance of DependenciesTable.
11 12 13 14 15 |
# File 'lib/delta_test/dependencies_table.rb', line 11 def initialize super self.default_proc = DEFAULT_PROC end |
Class Method Details
.load(file) ⇒ Object
Restore a table object from a file
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/delta_test/dependencies_table.rb', line 22 def self.load(file) begin data = File.binread(file) dt = Marshal.load(data) dt.default_proc = DEFAULT_PROC dt rescue self.new end end |
Instance Method Details
#add(spec_file, source_file) ⇒ Object
Add a dependency for a spec file
39 40 41 42 |
# File 'lib/delta_test/dependencies_table.rb', line 39 def add(spec_file, source_file) source_file = Utils.regulate_filepath(source_file, DeltaTest.config.base_path) self[spec_file] << source_file if DeltaTest.config.filtered_files.include?(source_file) end |
#cleanup! ⇒ Object
Cleanup empty sets from the table
78 79 80 |
# File 'lib/delta_test/dependencies_table.rb', line 78 def cleanup! self.reject! { |k, v| v.empty? } end |
#dump(file) ⇒ Object
Dump the table object to a file
87 88 89 90 91 92 93 94 |
# File 'lib/delta_test/dependencies_table.rb', line 87 def dump(file) without_default_proc do cleanup! data = Marshal.dump(self) FileUtils.mkdir_p(File.dirname(file)) File.open(file, 'wb') { |f| f.write data } end end |
#reverse_merge!(other) ⇒ Object
Reverse merge other table
49 50 51 52 53 54 55 56 57 |
# File 'lib/delta_test/dependencies_table.rb', line 49 def reverse_merge!(other) raise TypeError unless other.is_a?(self.class) other.each do |spec_file, source_files| self[spec_file] |= source_files end nil end |
#without_default_proc ⇒ Object
Temporary disable default_proc Because Marshal can’t dump Hash with default_proc
65 66 67 68 69 70 71 72 73 |
# File 'lib/delta_test/dependencies_table.rb', line 65 def without_default_proc self.default_proc = nil begin yield ensure self.default_proc = DEFAULT_PROC end end |