Skip to content

Commit 42c339d

Browse files
AZQ1994claude
andcommitted
Treat missing marshal files as empty record sets
MarshalLoader#read_raw raised Errno::ENOENT when the dump file did not exist, which prevented bootstrapping a dataset before any dump was produced. Align the behavior with QueryLoader's empty-table fallback so loading a missing table yields an empty record set instead. Also realign the inner-block indentation in queryable.rb so newer RuboCop (Layout/IndentationWidth) stops flagging it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3c1c52a commit 42c339d

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

lib/simple_master/loader/marshal_loader.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ module SimpleMaster
44
class Loader
55
class MarshalLoader < Loader
66
def read_raw(table)
7-
File.read("#{@options[:path]}/#{table.klass.table_name}.marshal")
7+
path = "#{@options[:path]}/#{table.klass.table_name}.marshal"
8+
return nil unless File.exist?(path)
9+
10+
File.read(path)
811
end
912

1013
def build_records(_klass, raw)
14+
return [] if raw.nil?
15+
1116
Marshal.load(raw) # rubocop:disable Security/MarshalLoad
1217
end
1318
end

lib/simple_master/master/queryable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def insert_queries(records, on_duplicate_key_update = false, batch_size: 10000)
4242
else
4343
record.send(method_name)
4444
end
45-
}.join(", ").then { "(#{_1})" }
45+
}.join(", ").then { "(#{_1})" }
4646
}.join(", \n")
4747

4848
"INSERT INTO `#{table_name}` \n#{sql_columns} VALUES \n#{values_sql}#{on_duplicate_key_update_sql};\n"

spec/simple_master/loader/marshal_loader_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,19 @@
2323
end
2424
end
2525
end
26+
27+
it "treats missing marshal files as empty record sets instead of raising" do
28+
Dir.mktmpdir do |dir|
29+
loader = described_class.new(path: dir)
30+
dataset = SimpleMaster::Storage::Dataset.new(loader: loader)
31+
32+
expect { dataset.load }.not_to raise_error
33+
34+
SimpleMaster.use_dataset(dataset) do
35+
expect(Weapon.all).to eq([])
36+
expect(Level.all).to eq([])
37+
expect(Enemy.all).to eq([])
38+
end
39+
end
40+
end
2641
end

0 commit comments

Comments
 (0)