Skip to content

Commit 4caf6b1

Browse files
committed
update rubocop
minor refactor in ContentTransferer
1 parent 37b3059 commit 4caf6b1

File tree

4 files changed

+44
-35
lines changed

4 files changed

+44
-35
lines changed

.rubocop.yml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ AllCops:
1717
TargetRubyVersion: 3.1
1818
SuggestExtensions: false
1919

20-
2120
Style/Documentation:
2221
Enabled: false
2322
StyleGuide: http://relaxed.ruby.style/#styledocumentation

.rubocop_todo.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-03-03 10:06:52 UTC using RuboCop version 1.60.2.
3+
# on 2024-03-04 19:34:06 UTC using RuboCop version 1.61.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -12,12 +12,12 @@ Lint/NestedMethodDefinition:
1212
Exclude:
1313
- 'lib/caramelize/filters/textile_to_markdown.rb'
1414

15-
# Offense count: 2
15+
# Offense count: 5
1616
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1717
Metrics/AbcSize:
1818
Max: 79
1919

20-
# Offense count: 1
20+
# Offense count: 2
2121
# Configuration parameters: CountComments, CountAsOne.
2222
Metrics/ClassLength:
2323
Max: 118
@@ -27,7 +27,7 @@ Metrics/ClassLength:
2727
Metrics/CyclomaticComplexity:
2828
Max: 9
2929

30-
# Offense count: 2
30+
# Offense count: 10
3131
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
3232
Metrics/MethodLength:
3333
Max: 102

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ GEM
123123
rubocop-ast (>= 0.4.0)
124124
rubocop-rake (0.6.0)
125125
rubocop (~> 1.0)
126-
rubocop-rspec (2.27.0)
126+
rubocop-rspec (2.27.1)
127127
rubocop (~> 1.40)
128128
rubocop-capybara (~> 2.17)
129129
rubocop-factory_bot (~> 2.22)

lib/caramelize/content_transferer.rb

+39-29
Original file line numberDiff line numberDiff line change
@@ -97,52 +97,62 @@ def commit_history_progress_bar
9797
def migrate_markup_of_latest_revisions
9898
puts 'Convert latest revisions:' if verbose?
9999
input_wiki.latest_revisions.each do |revision|
100-
if input_wiki.excluded_pages.include?(revision.title)
101-
puts "Exclude Page: #{revision.title}" if verbose?
102-
next
103-
end
104-
105-
if verbose?
106-
puts "Filter source: #{revision.title} #{revision.time}"
107-
else
108-
migrate_markup_progress_bar.increment
109-
end
110-
111-
migrate_markup_of_revision(revision)
100+
convert_markup_of_revision(revision)
112101
end
113102
end
114103

115104
def commit_history
116105
output_wiki.commit_history(revisions, options) do |page, index|
117-
if input_wiki.excluded_pages.include?(page.title)
118-
puts "Exclude Page: #{page.title}" if verbose?
119-
next
120-
end
121-
122-
if verbose?
123-
puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}"
124-
else
125-
commit_history_progress_bar.increment
126-
end
106+
commit_page(page, index)
127107
end
128108
end
129109

130-
def migrate_markup_of_revision(revision)
110+
def commit_page(page, index)
111+
if input_wiki.excluded_pages.include?(page.title)
112+
puts "Exclude Page: #{page.title}" if verbose?
113+
return
114+
end
115+
116+
if verbose?
117+
puts "(#{index + 1}/#{revisions_count}) #{page.time} #{page.title}"
118+
else
119+
commit_history_progress_bar.increment
120+
end
121+
end
122+
123+
def run_filter_processor_on_revision(revision)
131124
body_new = filter_processor.run(revision.body)
132125

133126
return if body_new == revision.body
134127

135-
message = "Markup of '#{revision.title}' converted to #{target_markup}"
128+
revision.message = "Markup of '#{revision.title}' converted to #{target_markup}"
129+
130+
commit_as_latest_page(revision)
131+
end
132+
133+
def convert_markup_of_revision(revision)
134+
if input_wiki.excluded_pages.include?(revision.title)
135+
puts "Exclude Page: #{revision.title}" if verbose?
136+
return
137+
end
138+
139+
if verbose?
140+
puts "Filter source: #{revision.title} #{revision.time}"
141+
else
142+
migrate_markup_progress_bar.increment
143+
end
144+
145+
run_filter_processor_on_revision(revision)
146+
end
136147

137-
# commit as latest page revision
138-
output_wiki.commit_revision(build_revision_metadata(revision, body_new, message), options[:markup])
148+
def commit_as_latest_page(revision)
149+
output_wiki.commit_revision(build_revision_metadata(revision, body_new), options[:markup])
139150
end
140151

141-
def build_revision_metadata(revision, body_new, message)
152+
def build_revision_metadata(revision, body_new)
142153
revision.body = body_new
143154
revision.author = { name: DEFAULT_AUTHOR_NAME, email: DEFAULT_AUTHOR_EMAIL }
144-
revision.time = Time.now
145-
revision.message = message
155+
revision.time = Time.zone.now
146156

147157
revision
148158
end

0 commit comments

Comments
 (0)