Skip to content

Commit

Permalink
Deprecate old formatting rules in favour of format: (tonsky#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
antstorm authored Aug 16, 2018
1 parent c202aca commit 9da686c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/money/money/formatting_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def initialize(currency, *raw_rules)
@rules = localize_formatting_rules(@rules)
@rules = translate_formatting_rules(@rules) if @rules[:translate]
@rules[:format] ||= determine_format_from_formatting_rules(@rules)

warn_about_deprecated_rules(@rules)
end

def [](key)
Expand Down Expand Up @@ -63,8 +65,7 @@ def translate_formatting_rules(rules)
def localize_formatting_rules(rules)
if currency.iso_code == "JPY" && I18n.locale == :ja
rules[:symbol] = "円" unless rules[:symbol] == false
rules[:symbol_position] = :after
rules[:symbol_after_without_space] = true
rules[:format] = '%n%u'
end
rules
end
Expand Down Expand Up @@ -92,5 +93,19 @@ def symbol_position_from(rules)
:after
end
end

def warn_about_deprecated_rules(rules)
if rules.has_key?(:symbol_position)
warn '[DEPRECATION] `symbol_position:` option is deprecated - use `format` to specify the formatting template.'
end

if rules.has_key?(:symbol_before_without_space)
warn '[DEPRECATION] `symbol_before_without_space:` option is deprecated - use `format` to specify the formatting template.'
end

if rules.has_key?(:symbol_after_without_space)
warn '[DEPRECATION] `symbol_after_without_space:` option is deprecated - use `format` to specify the formatting template.'
end
end
end
end

0 comments on commit 9da686c

Please sign in to comment.