style: brace blocks for values, do...end for effects
Braces where the value's the point, do...end where it's not —
sixteen files re-hung on what each block had actually got.
The fixture stopped chaining .keys off an end, a smell of its own;
assert_raises goes by layout: braces inline, do...end once grown.
Assisted-by: Claude Opus 5 via Claude Code
diff --git a/lib/pro_tacts/admin/contacts_edit.rb b/lib/pro_tacts/admin/contacts_edit.rb
index a2aa367..f2132fa 100644
--- a/lib/pro_tacts/admin/contacts_edit.rb
+++ b/lib/pro_tacts/admin/contacts_edit.rb
@@ -178,7 +178,9 @@ module ProTacts
value: email.value, placeholder: "removed on save")
end
end
- @own.addresses.each { address_row(it) }
+ @own.addresses.each do
+ address_row(it)
+ end
birthday_row
added_rows
# The first NOTE the card carries: this row edits one,
diff --git a/lib/pro_tacts/admin/contacts_index.rb b/lib/pro_tacts/admin/contacts_index.rb
index e17badd..ef4d7ac 100644
--- a/lib/pro_tacts/admin/contacts_index.rb
+++ b/lib/pro_tacts/admin/contacts_index.rb
@@ -48,7 +48,11 @@ module ProTacts
if @rows.empty?
p(class: "type-body-sm") { @query.empty? ? "No contacts yet." : "No contacts match." }
else
- ul(class: "card") { @rows.each { render_row(it) } }
+ ul(class: "card") do
+ @rows.each do
+ render_row(it)
+ end
+ end
end
end
render UpcomingBirthdays.new(upcoming: @upcoming)
diff --git a/lib/pro_tacts/admin/contacts_show.rb b/lib/pro_tacts/admin/contacts_show.rb
index 7850ea9..a78a227 100644
--- a/lib/pro_tacts/admin/contacts_show.rb
+++ b/lib/pro_tacts/admin/contacts_show.rb
@@ -104,11 +104,19 @@ module ProTacts
# and a group holds only addresses and notes anyway (see
# db/migrations/004_groups.rb).
def rows
- @contact.phones.each { |phone| row(phone.type || "phone", phone.value, phone.line) }
- @contact.emails.each { |email| row(email.type || "email", email.value, email.line) }
- @contact.addresses.each { |address| row(address.type || "address", address_lines(address), address.line) }
+ @contact.phones.each do |phone|
+ row(phone.type || "phone", phone.value, phone.line)
+ end
+ @contact.emails.each do |email|
+ row(email.type || "email", email.value, email.line)
+ end
+ @contact.addresses.each do |address|
+ row(address.type || "address", address_lines(address), address.line)
+ end
row("birthday", @birthday) if @birthday
- @contact.notes.each { |note| row("notes", note.value, note.line) }
+ @contact.notes.each do |note|
+ row("notes", note.value, note.line)
+ end
end
# The type in one column and the value in the other, with the
@@ -148,7 +156,9 @@ module ProTacts
#: (String | Array[String] value) -> void
def render_value(value)
if value.is_a?(Array)
- value.each { |line| div { line } }
+ value.each do |line|
+ div { line }
+ end
else
div(style: "white-space: pre-wrap;") { value }
end
diff --git a/lib/pro_tacts/admin/icons.rb b/lib/pro_tacts/admin/icons.rb
index e989366..fcb3ba9 100644
--- a/lib/pro_tacts/admin/icons.rb
+++ b/lib/pro_tacts/admin/icons.rb
@@ -35,7 +35,9 @@ module ProTacts
svg(viewBox: "0 0 24 24", width: @size, height: @size, fill: :none,
stroke: "currentColor", stroke_width: 2, stroke_linecap: "round",
stroke_linejoin: "round", aria_hidden: true) do
- PATHS.fetch(@name).each { path(d: it) }
+ PATHS.fetch(@name).each do
+ path(d: it)
+ end
end
end
end
diff --git a/lib/pro_tacts/admin/upcoming_birthdays.rb b/lib/pro_tacts/admin/upcoming_birthdays.rb
index d44bf6f..b1df606 100644
--- a/lib/pro_tacts/admin/upcoming_birthdays.rb
+++ b/lib/pro_tacts/admin/upcoming_birthdays.rb
@@ -25,7 +25,11 @@ module ProTacts
if @upcoming.empty?
p(class: "type-body-sm") { "No birthdays to show." }
else
- ul(class: "card") { @upcoming.each { render_row(it) } }
+ ul(class: "card") do
+ @upcoming.each do
+ render_row(it)
+ end
+ end
end
end
end
diff --git a/lib/pro_tacts/contact.rb b/lib/pro_tacts/contact.rb
index 7396880..3dd5797 100644
--- a/lib/pro_tacts/contact.rb
+++ b/lib/pro_tacts/contact.rb
@@ -276,34 +276,34 @@ module ProTacts
#: () -> Array[Phone]
def phones
- of_line("TEL").filter_map do |line|
+ of_line("TEL").filter_map { |line|
property = line.property
next if property.nil?
value = text_of(property)
Phone.new(value:, type: type_of(property), line:) if value
- end
+ }
end
#: () -> Array[Email]
def emails
- of_line("EMAIL").filter_map do |line|
+ of_line("EMAIL").filter_map { |line|
property = line.property
next if property.nil?
value = text_of(property)
Email.new(value:, type: type_of(property), line:) if value
- end
+ }
end
#: () -> Array[Address]
def addresses
- of_line("ADR").filter_map do |line|
+ of_line("ADR").filter_map { |line|
property = line.property
next if property.nil?
address_of(property, line:)
- end
+ }
end
# The card's NOTEs (RFC 2426 section 3.6.2), in text form. Every
@@ -315,13 +315,13 @@ module ProTacts
# which is always the group's (see #vcard).
#: () -> Array[Note]
def notes
- of_line("NOTE").filter_map do |line|
+ of_line("NOTE").filter_map { |line|
property = line.property
next if property.nil?
value = text_of(property)
Note.new(value:, line:) if value
- end
+ }
end
# The name of the group a composed line came from, or nil for a
diff --git a/lib/pro_tacts/store.rb b/lib/pro_tacts/store.rb
index f1a7a85..d4d2188 100644
--- a/lib/pro_tacts/store.rb
+++ b/lib/pro_tacts/store.rb
@@ -354,7 +354,9 @@ module ProTacts
def rebuild_index
@database.transaction do
card_properties.delete
- cards.order(:id).all.each { reindex(it.fetch(:id).to_s, VCard.new(it.fetch(:vcard).to_s)) }
+ cards.order(:id).all.each do
+ reindex(it.fetch(:id).to_s, VCard.new(it.fetch(:vcard).to_s))
+ end
end
end
diff --git a/lib/pro_tacts/unhandled_requests.rb b/lib/pro_tacts/unhandled_requests.rb
index d064fcf..1dfd22b 100644
--- a/lib/pro_tacts/unhandled_requests.rb
+++ b/lib/pro_tacts/unhandled_requests.rb
@@ -41,7 +41,9 @@ module ProTacts
return [status, headers, body] unless self.class.capture?(status)
parts = [] #: Array[String]
- body.each { parts << it }
+ body.each do
+ parts << it
+ end
# See DebugLogger#log_response: respond_to? cannot narrow an
# interface, so the cast stands for the check beside it.
(_ = body).close if body.respond_to?(:close)
diff --git a/lib/pro_tacts/vcard.rb b/lib/pro_tacts/vcard.rb
index 887c8a0..673d471 100644
--- a/lib/pro_tacts/vcard.rb
+++ b/lib/pro_tacts/vcard.rb
@@ -82,10 +82,10 @@ module ProTacts
#: (Parser::Property property) -> String
def self.header_of(property)
prefix = property.group ? "#{property.group}." : ""
- parameters = property.parameters.map do |name, value|
+ parameters = property.parameters.map { |name, value|
bare = /\A#{Parser::PTEXT}\z/.match?(value)
";#{name}=#{bare ? value : "\"#{value}\""}"
- end
+ }
"#{prefix}#{property.name}#{parameters.join}:"
end
diff --git a/lib/pro_tacts/web.rb b/lib/pro_tacts/web.rb
index 73a6c98..47323d8 100644
--- a/lib/pro_tacts/web.rb
+++ b/lib/pro_tacts/web.rb
@@ -419,10 +419,10 @@ module ProTacts
elsif (sequence = token[%r{\Ahttp://pro-tacts/sync/(\d+)\z}, 1]) &&
sequence.to_i <= store.latest_sequence
net = store.changes(after: sequence.to_i).map { it.card_id }.uniq
- responses = net.map do |id|
+ responses = net.map { |id|
contact = contacts.find { it.id == id }
contact ? etag_response(contact) : missing_response(contact_href(id))
- end
+ }
multistatus(responses, sync_token:)
else
# A token this server never issued, or one naming a state
@@ -780,10 +780,10 @@ module ProTacts
# because the field is a list and a request carrying one value
# is still a list of one.
submitted = Array(params["new_phone"]) #: Array[untyped]
- added = submitted.filter_map do
+ added = submitted.filter_map {
value = it.to_s.strip
"TEL:#{VCard.escape(value)}\r\n" unless value.empty?
- end #: Array[String]
+ } #: Array[String]
card.insert(added)
end
@@ -808,10 +808,10 @@ module ProTacts
end
submitted = Array(params["new_email"]) #: Array[untyped]
- added = submitted.filter_map do
+ added = submitted.filter_map {
value = it.to_s.strip
"EMAIL:#{VCard.escape(value)}\r\n" unless value.empty?
- end #: Array[String]
+ } #: Array[String]
card.insert(added)
end
@@ -849,9 +849,9 @@ module ProTacts
#: (Contact::Address address, untyped submitted) -> bool
def address_unchanged?(address, submitted)
- ADDRESS_COMPONENTS.keys.all? do |name|
+ ADDRESS_COMPONENTS.keys.all? { |name|
submitted[name].to_s.strip == address.public_send(name).to_s
- end
+ }
end
# One address row's replacement line: the raw components spliced
diff --git a/test/fixture_data.rb b/test/fixture_data.rb
index 2fe8e1b..a0d6025 100644
--- a/test/fixture_data.rb
+++ b/test/fixture_data.rb
@@ -84,10 +84,11 @@ module FixtureData
FileUtils.mkdir_p(directory)
store = ProTacts::Store.at(directory / "contacts.db")
- ids = cards.each do |id, card|
+ seed = cards
+ seed.each do |id, card|
store.put(id, card)
- end.keys
- backdate(store, ids)
+ end
+ backdate(store, seed.keys)
seed_groups(store)
store
end
diff --git a/test/pro_tacts/admin/test_contacts_pages.rb b/test/pro_tacts/admin/test_contacts_pages.rb
index 7a3e4dc..2b428e1 100644
--- a/test/pro_tacts/admin/test_contacts_pages.rb
+++ b/test/pro_tacts/admin/test_contacts_pages.rb
@@ -36,7 +36,9 @@ class AdminContactsPagesTest < Minitest::Test
ProTacts::Store.connect(Pathname.new(dir) / "contacts.db") do |store|
ProTacts::Web.store = store
- cards.each { |id, card| store.put(id, card) }
+ cards.each do |id, card|
+ store.put(id, card)
+ end
yield store
ensure
ProTacts::Web.store = original
@@ -55,8 +57,12 @@ class AdminContactsPagesTest < Minitest::Test
def add_group(store, name:, members:, lines:)
database = store.instance_variable_get(:@database)
database[:groups].insert(id: "household", name:)
- lines.each.with_index { |line, position| database[:group_properties].insert(group_id: "household", position:, line:) }
- members.each { |card_id| database[:group_members].insert(group_id: "household", card_id:) }
+ lines.each.with_index do |line, position|
+ database[:group_properties].insert(group_id: "household", position:, line:)
+ end
+ members.each do |card_id|
+ database[:group_members].insert(group_id: "household", card_id:)
+ end
end
def test_index_lists_recently_updated_contacts
diff --git a/test/pro_tacts/test_store.rb b/test/pro_tacts/test_store.rb
index 6459622..bc35e01 100644
--- a/test/pro_tacts/test_store.rb
+++ b/test/pro_tacts/test_store.rb
@@ -58,11 +58,15 @@ class StoreTest < Minitest::Test
end
def test_an_empty_store_lists_no_contacts
- with_store { assert_empty it.contacts }
+ with_store do
+ assert_empty it.contacts
+ end
end
def test_a_missing_contact_is_nil
- with_store { assert_nil it.contact("nobody") }
+ with_store do
+ assert_nil it.contact("nobody")
+ end
end
## Pictures
@@ -166,7 +170,9 @@ class StoreTest < Minitest::Test
def test_a_card_survives_reopening_the_database
Dir.mktmpdir do |dir|
path = Pathname.new(dir) / "contacts.db"
- ProTacts::Store.connect(path) { it.put("aiden", AIDEN) }
+ ProTacts::Store.connect(path) do
+ it.put("aiden", AIDEN)
+ end
ProTacts::Store.connect(path) do |store|
assert_equal AIDEN, store.contact("aiden").vcard.to_s
@@ -858,9 +864,9 @@ class StoreTest < Minitest::Test
def test_upcoming_birthdays_take_the_first_n
september = Date.new(2026, 9, 3)
- cards = (1..3).to_h do |n|
+ cards = (1..3).to_h { |n|
["c#{n}", "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:Contact #{n}\r\nBDAY:1990-09-0#{n + 4}\r\nUID:c#{n}\r\nEND:VCARD\r\n"]
- end
+ }
with_store(cards) do |store|
assert_equal %w[c1 c2], store.upcoming_birthdays(2, today: september).map { it.contact.id }
@@ -934,8 +940,12 @@ class StoreTest < Minitest::Test
def add_group(store, id:, members:, lines:)
db = database(store)
db[:groups].insert(id:, name: id.capitalize)
- lines.each.with_index { |line, position| db[:group_properties].insert(group_id: id, position:, line:) }
- members.each { |card_id| db[:group_members].insert(group_id: id, card_id:) }
+ lines.each.with_index do |line, position|
+ db[:group_properties].insert(group_id: id, position:, line:)
+ end
+ members.each do |card_id|
+ db[:group_members].insert(group_id: id, card_id:)
+ end
end
# A member's served card is the stored one with the group's lines
diff --git a/test/pro_tacts/test_unhandled_requests.rb b/test/pro_tacts/test_unhandled_requests.rb
index a5818d7..03175ea 100644
--- a/test/pro_tacts/test_unhandled_requests.rb
+++ b/test/pro_tacts/test_unhandled_requests.rb
@@ -118,7 +118,9 @@ class UnhandledRequestsTest < Minitest::Test
def test_a_repeated_request_is_captured_once
@stub.status = 404
- 3.times { get "/dav/unknown/" }
+ 3.times do
+ get "/dav/unknown/"
+ end
assert_equal 1, captures.size
end
diff --git a/test/pro_tacts/test_warnings.rb b/test/pro_tacts/test_warnings.rb
index e769baa..b68fcd1 100644
--- a/test/pro_tacts/test_warnings.rb
+++ b/test/pro_tacts/test_warnings.rb
@@ -7,14 +7,20 @@ require_relative "../test_helper"
class ProTactsWarningsTest < Minitest::Test
def test_silences_warnings_for_the_block_and_restores_them_after
verbose = $VERBOSE
- ProTacts.silence_warnings { assert_nil $VERBOSE }
+ ProTacts.silence_warnings do
+ assert_nil $VERBOSE
+ end
assert_equal verbose, $VERBOSE
end
def test_restores_warnings_when_the_block_raises
verbose = $VERBOSE
- assert_raises(RuntimeError) { ProTacts.silence_warnings { raise "boom" } }
+ assert_raises(RuntimeError) do
+ ProTacts.silence_warnings do
+ raise "boom"
+ end
+ end
assert_equal verbose, $VERBOSE
end
diff --git a/test/pro_tacts/test_web.rb b/test/pro_tacts/test_web.rb
index 79a74ec..0efb48d 100644
--- a/test/pro_tacts/test_web.rb
+++ b/test/pro_tacts/test_web.rb
@@ -851,7 +851,9 @@ class WebTest < Minitest::Test
store.put("aiden", card("aiden", "Aiden Smith"))
after = read_tags.call
- before.zip(after).each { refute_equal it.first, it.last }
+ before.zip(after).each do
+ refute_equal it.first, it.last
+ end
end
end
end