Skip to content

Commit 4342d52

Browse files
committed
Initialize Store's state with the given options object
1 parent 7aae2f6 commit 4342d52

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

lib/rdoc/rdoc.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,6 @@ def document options
460460
@last_modified = setup_output_dir @options.op_dir, @options.force_update
461461
end
462462

463-
@store.encoding = @options.encoding
464-
@store.dry_run = @options.dry_run
465-
@store.main = @options.main_page
466-
@store.title = @options.title
467-
@store.path = @options.op_dir
468-
469463
@start_time = Time.now
470464

471465
@store.load_cache

lib/rdoc/rubygems_hook.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,7 @@ def generate
188188
@rdoc = new_rdoc
189189
@rdoc.options = options
190190

191-
store = RDoc::Store.new(options)
192-
store.encoding = options.encoding
193-
store.dry_run = options.dry_run
194-
store.main = options.main_page
195-
store.title = options.title
196-
197-
@rdoc.store = store
191+
@rdoc.store = RDoc::Store.new(options)
198192

199193
say "Parsing documentation for #{@spec.full_name}"
200194

lib/rdoc/store.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ def message # :nodoc:
121121
# Creates a new Store of +type+ that will load or save to +path+
122122

123123
def initialize(options, path: nil, type: nil)
124-
@dry_run = false
125-
@encoding = nil
126-
@path = path
127-
@type = type
128124
@options = options
125+
@dry_run = options.dry_run
126+
@encoding = options.encoding
127+
@path = path || options.op_dir
128+
@type = type
129129

130130
@cache = {
131131
:ancestors => {},
@@ -135,10 +135,10 @@ def initialize(options, path: nil, type: nil)
135135
:c_singleton_class_variables => {},
136136
:encoding => @encoding,
137137
:instance_methods => {},
138-
:main => nil,
138+
:main => options.main_page,
139139
:modules => [],
140140
:pages => [],
141-
:title => nil,
141+
:title => options.title,
142142
}
143143

144144
@classes_hash = {}

test/rdoc/test_rdoc_store.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def assert_cache imethods, cmethods, attrs, modules,
9090
:class_methods => cmethods,
9191
:c_class_variables => {},
9292
:c_singleton_class_variables => {},
93-
:encoding => nil,
93+
:encoding => Encoding::UTF_8,
9494
:instance_methods => imethods,
9595
:modules => modules,
9696
:pages => pages,
@@ -447,6 +447,10 @@ def test_load_cache
447447
Marshal.dump cache, io
448448
end
449449

450+
# Store prioritize @encoding over the cached value
451+
# See we need to unset @encoding to test the cached value
452+
@s.encoding = nil
453+
450454
@s.load_cache
451455

452456
assert_equal cache, @s.cache
@@ -497,7 +501,7 @@ def test_load_cache_no_cache
497501
:class_methods => {},
498502
:c_class_variables => {},
499503
:c_singleton_class_variables => {},
500-
:encoding => nil,
504+
:encoding => Encoding::UTF_8,
501505
:instance_methods => {},
502506
:main => nil,
503507
:modules => [],
@@ -530,6 +534,10 @@ def test_load_cache_legacy
530534
Marshal.dump cache, io
531535
end
532536

537+
# Store prioritize @encoding over the cached value
538+
# See we need to unset @encoding to test the cached value
539+
@s.encoding = nil
540+
533541
@s.load_cache
534542

535543
expected = {
@@ -685,7 +693,7 @@ def test_save
685693
},
686694
:main => nil,
687695
:modules => %w[Mod Object Object::SubClass],
688-
:encoding => nil,
696+
:encoding => Encoding::UTF_8,
689697
:pages => %w[README.txt],
690698
:title => nil,
691699
}

0 commit comments

Comments
 (0)