Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ Style/SymbolArray:
# Prefer [:a, :b] to %i[a b]
EnforcedStyle: brackets

Style/TrailingCommaInArguments:
# Prefer trailing commas in multiline arguments:
# call(
# a: 1,
# b: 2,
# )
EnforcedStyleForMultiline: diff_comma

Style/TrailingCommaInArrayLiteral:
# Prefer trailing commas in arrays:
# [
# 1,
# 2,
# ]
EnforcedStyleForMultiline: diff_comma

Style/TrailingCommaInHashLiteral:
# Prefer trailing commas in multiline hashes:
# {
# a: 1,
# b: 2,
# }
EnforcedStyleForMultiline: diff_comma

Style/YodaCondition:
# Sometimes in specs it makes more sense to write
# 2 >= Money.new(2, 'USD')
Expand Down
14 changes: 0 additions & 14 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/money/bank/variable_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def exchange_with(from, to_currency, &block)
from.dup_with(
fractional: exchange(fractional, rate, &block),
currency: to_currency,
bank: self
bank: self,
)
else
raise UnknownRate, "No conversion rate known for '#{from.currency.iso_code}' -> '#{to_currency}'"
Expand Down
2 changes: 1 addition & 1 deletion lib/money/money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def dup_with(options = {})
self.class.new(
options[:fractional] || fractional,
options[:currency] || currency,
bank: options[:bank] || bank
bank: options[:bank] || bank,
)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/money/money/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Money
class Formatter
DEFAULTS = {
thousands_separator: '',
decimal_mark: '.'
decimal_mark: '.',
}.freeze

# Creates a formatted price string according to several rules.
Expand Down Expand Up @@ -230,7 +230,7 @@ def format_number
[
html_wrap(whole_part, "whole"),
html_wrap(decimal_mark, "decimal-mark"),
html_wrap(decimal_part, "decimal")
html_wrap(decimal_part, "decimal"),
].join
end
else
Expand Down
2 changes: 1 addition & 1 deletion lib/money/money/locale_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Money
module LocaleBackend
BACKENDS = {
i18n: Money::LocaleBackend::I18n,
currency: Money::LocaleBackend::Currency
currency: Money::LocaleBackend::Currency,
}.freeze

def self.find(name)
Expand Down
12 changes: 6 additions & 6 deletions spec/currency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def to_s
subunit: "Centimes",
subunit_to_unit: 100,
decimal_mark: ",",
thousands_separator: " "
thousands_separator: " ",
)

expect(described_class.find_by_iso_numeric(250)).to eq described_class.new(:frf)
Expand All @@ -100,7 +100,7 @@ def to_s
name: "French Francs",
symbol: "FR",
subunit: "Centimes",
subunit_to_unit: 100
subunit_to_unit: 100,
)

expect(described_class.find_by_iso_numeric(250)).to eq described_class.new(:frf)
Expand Down Expand Up @@ -160,7 +160,7 @@ def to_s
iso_code: "XXX",
name: "Golden Doubloon",
symbol: "%",
subunit_to_unit: 100
subunit_to_unit: 100,
)
new_currency = described_class.find("XXX")
expect(new_currency).not_to be_nil
Expand All @@ -187,12 +187,12 @@ def to_s
iso_code: "XXX",
name: "Golden Doubloon",
symbol: "%",
subunit_to_unit: 100
subunit_to_unit: 100,
)
described_class.inherit(
"XXX",
iso_code: "YYY",
symbol: "@"
symbol: "@",
)
new_currency = described_class.find("YYY")
expect(new_currency).not_to be_nil
Expand Down Expand Up @@ -481,7 +481,7 @@ def to_s
:subunit => cad.subunit,
:subunit_to_unit => cad.subunit_to_unit,
:thousands_separator => cad.thousands_separator,
:decimal_mark => modified_mark
:decimal_mark => modified_mark,
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/locale_backend/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
before do
I18n.locale = :de
I18n.backend.store_translations(:de, number: {
currency: { format: { delimiter: '.', separator: ',', unit: '$', format: '%u%n' } }
currency: { format: { delimiter: '.', separator: ',', unit: '$', format: '%u%n' } },
})
end

Expand Down
6 changes: 3 additions & 3 deletions spec/money/allocation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
expect(parts.map { |x| x.round(10) }).to eq([
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333')
BigDecimal('33.3333333333'),
])
expect(parts.inject(0, :+)).to eq(amount)
end
Expand Down Expand Up @@ -126,7 +126,7 @@
expect(parts.map { |x| x.round(10) }).to eq([
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333'),
BigDecimal('33.3333333333')
BigDecimal('33.3333333333'),
])
expect(parts.inject(0, :+)).to eq(amount)
end
Expand Down Expand Up @@ -163,7 +163,7 @@
90.36, 90.36, 90.36, 90.36,
90.36, 90.36, 90.36, 90.36,
90.36, 90.36, 90.36, 90.36,
90.36
90.36,
]
end

Expand Down
4 changes: 2 additions & 2 deletions spec/money/formatting_rules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

it 'returns the translated format for the locale' do
I18n.backend.store_translations(:fr, number: {
currency: { format: { format: "%n %u" } }
currency: { format: { format: "%n %u" } },
})
currency = Money::Currency.new('EUR')
rules = { separator: '.', delimiter: ',' }
Expand All @@ -47,7 +47,7 @@
it 'returns the default format for the locale' do
allow(Money).to receive(:locale_backend).and_return(nil)
I18n.backend.store_translations(:fr, number: {
currency: { format: { format: "%n %u" } }
currency: { format: { format: "%n %u" } },
})
currency = Money::Currency.new('EUR')
rules = { separator: '.', delimiter: ',' }
Expand Down
8 changes: 4 additions & 4 deletions spec/money/formatting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
I18n.locale = :de
I18n.backend.store_translations(
:de,
number: { format: { delimiter: ".", separator: "," } }
number: { format: { delimiter: ".", separator: "," } },
)
end

Expand All @@ -66,7 +66,7 @@
I18n.locale = :de
I18n.backend.store_translations(
:de,
number: { currency: { format: { delimiter: ".", separator: "," } } }
number: { currency: { format: { delimiter: ".", separator: "," } } },
)
end

Expand All @@ -86,7 +86,7 @@
I18n.locale = :de
I18n.backend.store_translations(
:de,
number: { currency: { symbol: { CAD: "CAD$" } } }
number: { currency: { symbol: { CAD: "CAD$" } } },
)
end

Expand Down Expand Up @@ -550,7 +550,7 @@
I18n.locale = :de
I18n.backend.store_translations(
:de,
number: { currency: { format: { delimiter: ".", separator: "," } } }
number: { currency: { format: { delimiter: ".", separator: "," } } },
)
end

Expand Down
20 changes: 10 additions & 10 deletions spec/money_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@
expect(Money.from_amount(2.137).to_d).to eq 2.14
end

expect(
Money.rounding_mode
).to eq(BigDecimal::ROUND_DOWN), 'Outer mode should be restored after inner block'
expect(Money.rounding_mode)
.to eq(BigDecimal::ROUND_DOWN),
'Outer mode should be restored after inner block'
expect(Money.from_amount(2.137).to_d).to eq 2.13
end

expect(
Money.rounding_mode
).to eq(BigDecimal::ROUND_HALF_UP), 'Original mode should be restored after outer block'
expect(Money.rounding_mode)
.to eq(BigDecimal::ROUND_HALF_UP),
'Original mode should be restored after outer block'
expect(Money.from_amount(2.137).to_d).to eq 2.14
end

Expand All @@ -272,7 +272,7 @@
results.push({
set_rounding_mode: rounding_mode,
mode: Money.rounding_mode,
result: Money.from_amount(test_value).to_d
result: Money.from_amount(test_value).to_d,
})

# Sleep to allow interleaving with other thread
Expand All @@ -281,15 +281,15 @@
results.push({
set_rounding_mode: rounding_mode,
mode: Money.rounding_mode,
result: Money.from_amount(test_value).to_d
result: Money.from_amount(test_value).to_d,
})
end
end
end

[
test_money_with_rounding_mode.call(BigDecimal::ROUND_DOWN),
test_money_with_rounding_mode.call(BigDecimal::ROUND_UP)
test_money_with_rounding_mode.call(BigDecimal::ROUND_UP),
].each(&:join)

all_results = []
Expand Down Expand Up @@ -356,7 +356,7 @@
thread_id: Thread.current.object_id,
expected: expected_bank,
actual: actual_bank,
match: expected_bank == actual_bank
match: expected_bank == actual_bank,
}
results_mutex.synchronize do
results << result
Expand Down