mirror of
https://github.com/we-promise/sure.git
synced 2026-05-07 12:54:04 +00:00
* feat(entries): Add amount validation and robustify monetizable concern * fix(valuations): localize blank amount errors --------- Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> Co-authored-by: SureBot <sure-bot@we-promise.com>
23 lines
441 B
Ruby
23 lines
441 B
Ruby
module Monetizable
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
def monetize(*fields)
|
|
fields.each do |field|
|
|
define_method("#{field}_money") do |**args|
|
|
value = self.send(field, **args)
|
|
|
|
return nil if value.blank? || monetizable_currency.nil?
|
|
|
|
Money.new(value, monetizable_currency)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
def monetizable_currency
|
|
currency
|
|
end
|
|
end
|