bigdecimal-pure 0.2.0 → 0.2.1

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: cf29bb03b15bb0bb1cbe340b2bc5a861f691af86d725f0d05122874ed2daeb64
4
- data.tar.gz: 604104049ea023a06615056a809cd806ac446e7214d2ac8164002b4a232068ab
3
+ metadata.gz: 22c794c8bb08894ae6b3cc7b6b26e9d01591dd6a47927669f10a8b80b184f9bd
4
+ data.tar.gz: acc8365df54d360ba92f333badd3e821f76245024b2bf97d23f209ea6c10a04f
5
5
  SHA512:
6
- metadata.gz: b15e47a6978178e1199b4d51403b5fb5dfe3e9728d5ec7e165c358a91bd956b31e391a48708e94c2225079790797d5840e2e32e92969c35c78900ec5c34d4180
7
- data.tar.gz: ea5fe695be57c79f4d3e45c5a609ffc8fec9464f025059c15dcedf8ed625dbc3ced159b5c0a7717161fa21295f741f191d4b987422571b8326e737cc45e15696
6
+ metadata.gz: ccd7018b72e5d0076ba156343efe374ac8f669734b16e0075b26273c6080b180398901ce8a2c1a22ed7d53455875984d7c445b34c007d87e6f0857e10840c133
7
+ data.tar.gz: 53c920c9dd094a2a7395c0de698f68975920db2a3101abdfb452af66a95add1f9bc6c116d03bae871f3f74e3cafeb2fb926ff48b5ebb021fa622ebca52d3c51b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.1] - 2026-10-16
4
+
5
+ - `require 'bigdecimal'` falls back to the pure class when the native
6
+ bigdecimal gem's Ruby files are on the load path but its C extension does
7
+ not load. This is what a Bundler-built ruby.wasm looks like when another gem
8
+ depends on bigdecimal: the gem is installed, `bigdecimal.so` is not, and
9
+ 0.2.0 raised `LoadError: cannot load such file -- bigdecimal.so`.
10
+
3
11
  ## [0.2.0] - 2026-09-30
4
12
 
5
13
  The pure class now does what bigdecimal 4.x does, where 0.1.0 did not:
@@ -32,5 +40,6 @@ ruby.wasm.
32
40
  - First release: BigDecimal in pure Ruby on Rational, taken from the ruby.wasm
33
41
  sandbox of Ren. `require 'bigdecimal'` prefers the native gem when installed.
34
42
 
43
+ [0.2.1]: https://github.com/Largo/bigdecimal-pure/releases/tag/v0.2.1
35
44
  [0.2.0]: https://github.com/Largo/bigdecimal-pure/releases/tag/v0.2.0
36
45
  [0.1.0]: https://github.com/Largo/bigdecimal-pure/releases/tag/v0.1.0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BigDecimalPure
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -16,15 +16,20 @@ module BigDecimalPure
16
16
  def native? = defined?(::BigDecimal) && !pure? ? true : false
17
17
 
18
18
  # Loads the native `feature` ("bigdecimal", "bigdecimal/util", ...), or
19
- # returns false when there is none. BIGDECIMAL_PURE=1 forces false.
19
+ # returns false when there is none or it does not load. BIGDECIMAL_PURE=1
20
+ # forces false.
21
+ #
22
+ # The native gem's Ruby files can be there without its C extension: a
23
+ # Bundler-built ruby.wasm installs the bigdecimal gem when another gem
24
+ # depends on it, but has no bigdecimal.so. Its bigdecimal.rb then raises
25
+ # LoadError on `require 'bigdecimal.so'`, and the pure class has to load.
20
26
  def require_native(feature)
21
27
  return false if ENV['BIGDECIMAL_PURE'] == '1'
22
28
 
23
29
  activate_native_gem
24
30
  path = native_path(feature)
25
31
  if path
26
- require path
27
- true
32
+ require_native_file(path, feature)
28
33
  elsif feature == 'bigdecimal'
29
34
  require_native_extension
30
35
  else
@@ -32,6 +37,17 @@ module BigDecimalPure
32
37
  end
33
38
  end
34
39
 
40
+ # `require path`, false on LoadError. A BigDecimal that the failed file
41
+ # left half defined is removed, so the pure class can take its place.
42
+ def require_native_file(path, feature)
43
+ had_bigdecimal = defined?(::BigDecimal)
44
+ require path
45
+ true
46
+ rescue LoadError
47
+ Object.send(:remove_const, :BigDecimal) if feature == 'bigdecimal' && !had_bigdecimal && defined?(::BigDecimal)
48
+ false
49
+ end
50
+
35
51
  # The bigdecimal gem, installed next to this one: put its lib on the load
36
52
  # path. Under Bundler this only works if it is in the bundle, which is right.
37
53
  def activate_native_gem
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigdecimal-pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - Andi
7
+ - Andi Idogawa
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -14,7 +14,7 @@ description: "`require 'bigdecimal'` loads the native bigdecimal when it is inst
14
14
  limit and BigMath to any precision included, for ruby.wasm and other places without
15
15
  a C compiler."
16
16
  email:
17
- - andi@idogawa.com
17
+ - web@idogawa.com
18
18
  executables: []
19
19
  extensions: []
20
20
  extra_rdoc_files: []