Skip to content

Commit 28f5c83

Browse files
authored
Merge pull request #7 from aktsk/fix-marshal-loader-missing-file
Treat missing marshal files as empty record sets
2 parents 3c1c52a + b437d49 commit 28f5c83

6 files changed

Lines changed: 45 additions & 3 deletions

File tree

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Style/Lambda:
6060
Style/MultilineBlockChain:
6161
Enabled: false
6262

63+
Style/OneClassPerFile:
64+
Enabled: false
65+
6366
Style/StringLiterals:
6467
Enabled: false
6568

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.1] - 2026-05-18
9+
10+
### Fixed
11+
- `MarshalLoader` no longer raises `Errno::ENOENT` when a dump file is missing; the corresponding table is loaded as an empty record set, matching `QueryLoader`'s fallback for unavailable tables.
12+
13+
## [1.0.0] - 2025-12-26
14+
15+
### Added
16+
- Initial public release.
17+
18+
[1.0.1]: https://github.com/aktsk/simple_master/compare/v1.0.0...v1.0.1
19+
[1.0.0]: https://github.com/aktsk/simple_master/releases/tag/v1.0.0

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"

lib/simple_master/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SimpleMaster
4-
VERSION = "1.0.0"
4+
VERSION = "1.0.1"
55
end

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)