money_attribute 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8058c06f7d8fd8f12abbe12c979efc9802cd56dcd788bf4f83e100838275d0fa
4
- data.tar.gz: '09ade456fbca1582b9f600858177bf20f049d24d35f8539967fce3989d445534'
3
+ metadata.gz: 874e817fa1e157ee49e460c8848dabff3fe525d9849571d21045de2694dd0770
4
+ data.tar.gz: 933dcdd5adc296d9aa635da79fc181e15652ed884c2e3b1231655a5652a2beca
5
5
  SHA512:
6
- metadata.gz: 1623898044fb45adb289c256683e7843365b078ecb840d5bc7e178995f7a9580aa6df92baa65a5ead5d45cd00ae8aa496062f9579ece5e9f960b9b64a3814fda
7
- data.tar.gz: 48a8712ec075f95c446265c14813067f4c3ff7dd8f76bad2dba5887685235481ac95a57c0c24542ec913a0b3b4153eb9ed7187ca1cfcad74d73ec2cfbbf190ea
6
+ metadata.gz: b5547742974245c1cffd5b690fa4c763e79224e553c90c2e19e88cdccb0d2c7ccdf669f9000e1917abe01fb880c2a50b0b2b475ffebf3fdfe01b787b0f4630ad
7
+ data.tar.gz: d0b760447e051fb0a1dc15492ba737676af935443ad5dcec4fb18988c898db37bf5980781d52cc64a4c60c651d03646ad77bb63ffdb6cb046c6d19f67cc7d092
@@ -53,11 +53,9 @@ module MoneyAttribute
53
53
  "Found: #{attribute_names.join(', ')}"
54
54
  end
55
55
 
56
- def amount_extractor_for(column_name)
57
- integer_column?(column_name) ? :fractional : :to_d
58
- end
56
+ def amount_extractor_for(column_name) = integer_column?(column_name) ? :subunits : :to_d
59
57
 
60
- def money_constructor_for(amount_column) = integer_column?(amount_column) ? :from_fractional : :from
58
+ def money_constructor_for(amount_column) = integer_column?(amount_column) ? :from_subunits : :from
61
59
 
62
60
  def integer_column?(column_name)
63
61
  col = columns.find { |c| c.name == column_name }
@@ -27,8 +27,15 @@ module MoneyAttribute
27
27
  amount_opts[:type] = col_type
28
28
 
29
29
  if options.key?(:amount) && options[:amount].is_a?(Hash)
30
- amount_opts[:null] = options[:amount][:null] if options[:amount].key?(:null)
31
- amount_opts[:default] = options[:amount][:default] if options[:amount].key?(:default)
30
+ amount_opts[:null] = options[:amount][:null] if options[:amount].key?(:null)
31
+ amount_opts[:default] = options[:amount][:default] if options[:amount].key?(:default)
32
+ amount_opts[:precision] = options[:amount][:precision] if options[:amount].key?(:precision)
33
+ amount_opts[:scale] = options[:amount][:scale] if options[:amount].key?(:scale)
34
+ end
35
+
36
+ if col_type == :decimal && !amount_opts.key?(:precision) && !amount_opts.key?(:scale)
37
+ amount_opts[:precision] = 16
38
+ amount_opts[:scale] = 4
32
39
  end
33
40
 
34
41
  currency_opts = {}
@@ -26,7 +26,7 @@ module MoneyAttribute
26
26
  return nil unless value
27
27
 
28
28
  if @column_type.is_a?(ActiveRecord::Type::Integer)
29
- ::Mint::Money.from_fractional(value, @currency)
29
+ ::Mint::Money.from_subunits(value, @currency)
30
30
  else
31
31
  ::Mint::Money.from(value, @currency)
32
32
  end
@@ -36,7 +36,7 @@ module MoneyAttribute
36
36
  return nil unless value
37
37
 
38
38
  if @column_type.is_a?(ActiveRecord::Type::Integer)
39
- value.fractional
39
+ value.subunits
40
40
  else
41
41
  value.to_d
42
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MoneyAttribute
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilson Ferraz
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 1.8.1
18
+ version: 1.9.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 1.8.1
25
+ version: 1.9.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
28
  requirement: !ruby/object:Gem::Requirement