minting 1.9.3 → 1.9.4

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: f42e86d079045c4e58c7aee230b1faf32eadc6f6ff33c455f2cfb81fce2894c6
4
- data.tar.gz: a06f2900dfe2f743fead4ca7927fdc81b4f9e30e5a51accce428fc78a2315a5e
3
+ metadata.gz: e784f15a78d9890f02c3b44c95ab975bd8a12647c27d87531059603fa0e5cab5
4
+ data.tar.gz: 83e28899e8e8cedcd98a93fd2b787470485d8f440ba82f63138499dc1ba33c20
5
5
  SHA512:
6
- metadata.gz: 46c5191a5990bf2fec8ca67dcac3cab9fade07d6638b817cf91ce49df40dc63c0e1efbc22eabd776c48d7559912ec7ed82f9ea47d8c7915a5fb76fa9a3e85a9a
7
- data.tar.gz: bd11d6eab450a072a299949157ec18b3d23c9c4283fbd06180121a29c01ed1c953f9ba69aceaf0d4261c1438aa330ff0aa56a044a5e724e4b834c100524586dd
6
+ metadata.gz: dc823a1170e16ae3ef0751d2e35200b681e89c42d8480d7dfb6117c9f7b6dbe8b6d5cec2fa47a57755e0f52eeb0324a5dd560a359729307aa19186625490f6fc
7
+ data.tar.gz: a281aae01fc2e2472c0697ea02f6d68f21c64ecb9acb9c8704a70bba35a8e7dafa0523f8d6696c93c818c67488c81c6c2b3d117cc48a5f0720eeaaa31607dac1
data/README.md CHANGED
@@ -30,7 +30,7 @@ Minting is faster than the Money gem for everyday operations and **over 10× fas
30
30
  Intuitive interface, descriptive error messages, and sensible defaults. Works the way you expect.
31
31
 
32
32
  ### Rails-ready
33
- Use with the [minting-rails](https://github.com/gferraz/minting-rails) companion gem for drop-in ActiveRecord type casting, validators, and form helpers.
33
+ Use with the [attribute-money](https://github.com/gferraz/attribute-money) companion gem for drop-in ActiveRecord type casting, validators, and form helpers.
34
34
 
35
35
  ### Quality code
36
36
  - **100% test coverage** — every line exercised
@@ -110,7 +110,7 @@ price_in_euros.to_formatted_s(format: '%<symbol>2s%<amount>+10f') #=> " €
110
110
 
111
111
  # Integral & fractional parts
112
112
  price.to_formatted_s(format: '%<integral>d %<fractional>d/100') #=> "9 99/100"
113
- Mint.money(0.99, 'USD').to_s(format: '%<integral>d dollars and %<fractional>02d cents')
113
+ Mint.money(0.99, 'USD').to_fs(format: '%<integral>d dollars and %<fractional>02d cents')
114
114
  #=> "0 dollars and 99 cents"
115
115
 
116
116
  # Per-sign Hash format (e.g. accounting parentheses for losses)
@@ -227,33 +227,32 @@ Modes: `:half_up` (default), `:half_down`, `:floor`, `:ceil`, `:truncate`, `:dow
227
227
 
228
228
  ## Optional top-level `Money` and `Currency`
229
229
 
230
- By default, Minting keeps everything namespaced under `Mint` to coexist nicely with other gems. If you prefer shorter constants, opt in:
230
+ By default, `require "minting"` exposes `Mint::Money` as the top-level `Money` constant, so you can write `Money.from(10, "USD")` directly:
231
231
 
232
232
  ```ruby
233
233
  require "minting"
234
- require "minting/dsl" # opt‑in top‑level Money / Currency
234
+
235
+ price = Money.from(10, "USD") # equivalent to Mint::Money.from
236
+ tax = Money.from(2.50, "USD")
235
237
  ```
236
238
 
237
- Or at runtime:
239
+ `Currency` is **not** auto-bound, because application domain models are commonly named `Currency` (e.g. a Rails model). To opt in to the top-level `Currency` constant:
238
240
 
239
241
  ```ruby
240
- Minting.use_top_level_constants!
242
+ require "minting"
243
+ require "minting/mint/aliases" # opt-in top-level Currency
244
+
245
+ cur = Currency.new(code: "EUR", symbol: "€", subunit: 2, priority: 0)
241
246
  ```
242
247
 
243
- For Rails applications, you can enable the top-level constants in an initializer:
248
+ For Rails applications, you can enable the top-level `Currency` constant in an initializer:
244
249
 
245
250
  ```ruby
246
251
  # config/initializers/minting.rb
247
- require "minting/dsl"
252
+ require "minting/mint/aliases"
248
253
  ```
249
254
 
250
- After opting in:
251
-
252
- ```ruby
253
- price = Money.from(10, "USD") # equivalent to Mint::Money.from
254
- tax = Money.from(2.50, "USD")
255
- cur = Currency.new(code: "EUR", symbol: "€", subunit: 2, priority: 0)
256
- ```
255
+ If another `Money` is already defined when `require "minting"` runs (e.g. the `money` gem was loaded first), Minting warns and skips the auto-bind — use `Mint::Money` in that case. The same applies to `Currency` via `minting/mint/aliases`.
257
256
 
258
257
  **Good fit:** Application code, especially Rails apps.
259
258
  **Not recommended:** Reusable gems/libraries — stick to `Mint::Money` to avoid conflicts.
@@ -294,7 +294,7 @@ Your README is already strong. To push it over the top vs. `money` gem and frien
294
294
  - Always-exact `Rational` amounts.
295
295
  - Currency-agnostic zero.
296
296
  - Faster formatting (link benchmarks).
297
- - Separate `minting-rails` companion for clean Rails integration.
297
+ - Separate `attribute-money` companion for clean Rails integration.
298
298
 
299
299
  2. **Add “Common tasks” cheatsheet**
300
300
 
@@ -314,7 +314,7 @@ Your README is already strong. To push it over the top vs. `money` gem and frien
314
314
 
315
315
  3. **Prominent “Rails” heading**
316
316
 
317
- Right now you just mention `minting-rails`. Make it a full section:
317
+ Right now you just mention `attribute-money`. Make it a full section:
318
318
 
319
319
  - How to add gem.
320
320
  - Example migration / attribute definition (even if in the other repo, mirror one snippet here).
@@ -253,7 +253,7 @@ Multi-PR epic:
253
253
  1. `Mint::Bank` interface with `#exchange(money, target)`.
254
254
  2. `Mint::Bank::MemoryStore` (in-memory, good for tests).
255
255
  3. `Mint::Bank::ECB` or `Mint::Bank::OpenExchangeRates` (network).
256
- 4. Update `minting-rails` to expose bank config in the Railtie.
256
+ 4. Update `attribute-money` to expose bank config in the Railtie.
257
257
 
258
258
  ### P2-3 Reek / RuboCop tightening
259
259
 
@@ -1,10 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Optional toplevel aliases for application use.
4
- # Not required automatically.
5
-
6
- # Alias for {Mint::Money} — enables `Money.new(...)` shorthand.
7
- Money = Mint::Money
8
-
9
- # Alias for {Mint::Currency} — enables `Currency.new(...)` shorthand.
10
- Currency = Mint::Currency
3
+ # Optional top-level alias for Mint::Currency.
4
+ #
5
+ # Mint::Money is auto-bound as the top-level Money constant by
6
+ # `require 'minting'` (see lib/minting.rb). Currency is not auto-bound
7
+ # because application domain models are commonly named Currency (e.g. a
8
+ # Rails model). Require this file to opt in:
9
+ #
10
+ # require 'minting/mint/aliases'
11
+ #
12
+ if defined?(Currency) && Currency != Mint::Currency
13
+ warn "minting: top-level Currency is already defined (#{Currency}); skipping alias."
14
+ else
15
+ Currency = Mint::Currency unless defined?(Currency)
16
+ end
@@ -13,7 +13,7 @@ module Mint
13
13
  # When set, +#to_formatted_s+ and +#format+ use these values as fallbacks when the
14
14
  # corresponding parameter is not explicitly provided.
15
15
  #
16
- # @example Rails I18n integration (in minting-rails railtie)
16
+ # @example Rails I18n integration (in attribute-money railtie)
17
17
  # Mint.locale_backend = -> {
18
18
  # fmt = I18n.t('number.currency.format')
19
19
  # {
data/lib/minting/mint.rb CHANGED
@@ -5,7 +5,6 @@ require_relative 'currency/currency'
5
5
  require_relative 'mint/dsl/numeric'
6
6
  require_relative 'mint/dsl/range'
7
7
  require_relative 'mint/dsl/string'
8
- require_relative 'mint/dsl/top_level'
9
8
  require_relative 'mint/i18n'
10
9
  require_relative 'mint/mint'
11
10
  require_relative 'mint/parser/parser'
@@ -3,5 +3,5 @@
3
3
  # Root namespace for the Minting library.
4
4
  module Minting
5
5
  # Current version of the Minting gem.
6
- VERSION = '1.9.3'
6
+ VERSION = '1.9.4'
7
7
  end
data/lib/minting.rb CHANGED
@@ -2,3 +2,13 @@
2
2
 
3
3
  require 'minting/mint'
4
4
  require 'minting/version'
5
+
6
+ # By default, expose Mint::Money as the top-level Money constant for
7
+ # convenience. If Money is already defined (e.g. by the `money` gem), warn
8
+ # and skip so both libraries can coexist in the same process without
9
+ # corrupting either class.
10
+ if defined?(Money) && Money != Mint::Money
11
+ warn "minting: top-level Money is already defined (#{Money}); skipping auto-bind. Use Mint::Money."
12
+ else
13
+ Money = Mint::Money unless defined?(Money)
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minting
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilson Ferraz
@@ -74,7 +74,6 @@ files:
74
74
  - lib/minting/mint/dsl/numeric.rb
75
75
  - lib/minting/mint/dsl/range.rb
76
76
  - lib/minting/mint/dsl/string.rb
77
- - lib/minting/mint/dsl/top_level.rb
78
77
  - lib/minting/mint/i18n.rb
79
78
  - lib/minting/mint/mint.rb
80
79
  - lib/minting/mint/parser/parser.rb
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Mint refinements
4
- module Mint
5
- # Registers top-level ::Money and ::Currency constants as aliases for Mint's classes.
6
- #
7
- # @raise [NameError] if ::Money or ::Currency are already defined and differ
8
- def self.use_top_level_constants!
9
- if !defined?(::Money) && !defined?(::Currency)
10
- require 'minting/mint/aliases'
11
- elsif ::Money == Mint::Money && ::Currency == Mint::Currency
12
- warn 'Warning: Money and Currency already defined as Mint aliases, skipping'
13
- else
14
- raise NameError, 'Cannot define top-level Money or Currency constants: already defined'
15
- end
16
- end
17
- end