amounts 0.1.0 → 0.3.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +95 -0
  3. data/README.md +101 -6
  4. data/lib/amount/active_record/attribute_definition.rb +12 -8
  5. data/lib/amount/active_record/calculations.rb +127 -0
  6. data/lib/amount/active_record/dirty.rb +43 -0
  7. data/lib/amount/active_record/model.rb +12 -5
  8. data/lib/amount/active_record/persistence.rb +34 -0
  9. data/lib/amount/active_record/serialization.rb +57 -0
  10. data/lib/amount/active_record.rb +6 -0
  11. data/lib/amount/compact.rb +5 -1
  12. data/lib/amount/concerns/calculable.rb +4 -1
  13. data/lib/amount/concerns/exportable.rb +31 -0
  14. data/lib/amount/concerns/serializable.rb +18 -1
  15. data/lib/amount/display.rb +7 -4
  16. data/lib/amount/manifest.rb +128 -0
  17. data/lib/amount/registry.rb +9 -0
  18. data/lib/amount/version.rb +1 -1
  19. data/lib/amount.rb +5 -0
  20. data/test/amount/active_record/amount_validator_test.rb +8 -0
  21. data/test/amount/active_record/attribute_definition_test.rb +25 -0
  22. data/test/amount/active_record/calculations_test.rb +165 -0
  23. data/test/amount/active_record/dirty_test.rb +70 -0
  24. data/test/amount/active_record/model_test.rb +32 -0
  25. data/test/amount/active_record/persistence_test.rb +53 -0
  26. data/test/amount/active_record/serialization_test.rb +75 -0
  27. data/test/amount/compact_test.rb +22 -7
  28. data/test/amount/concerns/calculable_test.rb +33 -0
  29. data/test/amount/concerns/exportable_test.rb +25 -0
  30. data/test/amount/concerns/serializable_test.rb +42 -4
  31. data/test/amount/display_test.rb +42 -0
  32. data/test/amount/manifest_test.rb +325 -0
  33. data/test/amount/registry_test.rb +14 -0
  34. data/test/integration/postgresql_test.rb +30 -0
  35. data/test/support/active_record_test_support.rb +20 -0
  36. metadata +14 -2
@@ -17,6 +17,8 @@ AmountTestSupport.register_active_record_types!
17
17
  t.amount :amount, null: true
18
18
  t.amount :fee, symbol: :SOL, null: true
19
19
  t.amount :reserve, precision: 40, default: "USDC|1.25", null: false
20
+ t.amount :bonus, symbol: :SOL, null: true
21
+ t.integer :parent_id
20
22
  end
21
23
  end
22
24
 
@@ -26,6 +28,20 @@ class Holding < ::ActiveRecord::Base
26
28
  has_amount :reserve
27
29
  end
28
30
 
31
+ # Inherits Holding's amounts unchanged.
32
+ class SubHolding < Holding
33
+ end
34
+
35
+ # Adds an amount of its own on top of Holding's.
36
+ class BonusHolding < Holding
37
+ has_amount :bonus, symbol: :SOL
38
+ end
39
+
40
+ # Belongs to another holding, for grouping by an association.
41
+ class ChildHolding < Holding
42
+ belongs_to :parent, class_name: "Holding", optional: true
43
+ end
44
+
29
45
  class ValidatedHolding < ::ActiveRecord::Base
30
46
  self.table_name = "holdings"
31
47
 
@@ -49,6 +65,10 @@ class ValidatedHolding < ::ActiveRecord::Base
49
65
  }
50
66
  end
51
67
 
68
+ # Inherits ValidatedHolding's amounts and validations unchanged.
69
+ class SubValidatedHolding < ValidatedHolding
70
+ end
71
+
52
72
  # Empty tables and the ActiveRecord test types before each test; an empty
53
73
  # registry after it.
54
74
  module ActiveRecordTestSetup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amounts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seb Scholl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-02 00:00:00.000000000 Z
11
+ date: 2026-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -47,12 +47,16 @@ files:
47
47
  - lib/amount/active_record.rb
48
48
  - lib/amount/active_record/amount_validator.rb
49
49
  - lib/amount/active_record/attribute_definition.rb
50
+ - lib/amount/active_record/calculations.rb
51
+ - lib/amount/active_record/dirty.rb
50
52
  - lib/amount/active_record/locale/en.yml
51
53
  - lib/amount/active_record/migration_methods.rb
52
54
  - lib/amount/active_record/model.rb
55
+ - lib/amount/active_record/persistence.rb
53
56
  - lib/amount/active_record/railtie.rb
54
57
  - lib/amount/active_record/rspec.rb
55
58
  - lib/amount/active_record/rspec/matchers.rb
59
+ - lib/amount/active_record/serialization.rb
56
60
  - lib/amount/active_record/type.rb
57
61
  - lib/amount/compact.rb
58
62
  - lib/amount/concerns/allocatable.rb
@@ -60,6 +64,7 @@ files:
60
64
  - lib/amount/concerns/coercible.rb
61
65
  - lib/amount/concerns/constructible.rb
62
66
  - lib/amount/concerns/convertible.rb
67
+ - lib/amount/concerns/exportable.rb
63
68
  - lib/amount/concerns/formattable.rb
64
69
  - lib/amount/concerns/localizable.rb
65
70
  - lib/amount/concerns/orderable.rb
@@ -68,6 +73,7 @@ files:
68
73
  - lib/amount/concerns/serializable.rb
69
74
  - lib/amount/display.rb
70
75
  - lib/amount/locale.rb
76
+ - lib/amount/manifest.rb
71
77
  - lib/amount/parser.rb
72
78
  - lib/amount/registry.rb
73
79
  - lib/amount/registry/generated_constructors.rb
@@ -85,8 +91,12 @@ files:
85
91
  - lib/generators/amount/active_record/templates/registry.rb.tt
86
92
  - test/amount/active_record/amount_validator_test.rb
87
93
  - test/amount/active_record/attribute_definition_test.rb
94
+ - test/amount/active_record/calculations_test.rb
95
+ - test/amount/active_record/dirty_test.rb
88
96
  - test/amount/active_record/migration_methods_test.rb
89
97
  - test/amount/active_record/model_test.rb
98
+ - test/amount/active_record/persistence_test.rb
99
+ - test/amount/active_record/serialization_test.rb
90
100
  - test/amount/active_record/type_test.rb
91
101
  - test/amount/active_record_test.rb
92
102
  - test/amount/compact_test.rb
@@ -95,6 +105,7 @@ files:
95
105
  - test/amount/concerns/coercible_test.rb
96
106
  - test/amount/concerns/constructible_test.rb
97
107
  - test/amount/concerns/convertible_test.rb
108
+ - test/amount/concerns/exportable_test.rb
98
109
  - test/amount/concerns/formattable_test.rb
99
110
  - test/amount/concerns/localizable_test.rb
100
111
  - test/amount/concerns/orderable_test.rb
@@ -103,6 +114,7 @@ files:
103
114
  - test/amount/concerns/serializable_test.rb
104
115
  - test/amount/display_test.rb
105
116
  - test/amount/locale_test.rb
117
+ - test/amount/manifest_test.rb
106
118
  - test/amount/parser_test.rb
107
119
  - test/amount/registry/generated_constructors_test.rb
108
120
  - test/amount/registry_test.rb