bigdecimal-pure 0.1.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.
@@ -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,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigdecimal-pure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.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
11
11
  dependencies: []
12
12
  description: "`require 'bigdecimal'` loads the native bigdecimal when it is installed
13
- and a pure Ruby BigDecimal on Rational otherwise, for ruby.wasm and other places
14
- without a C compiler."
13
+ and otherwise a pure Ruby BigDecimal that behaves like bigdecimal 4.x, NaN, modes,
14
+ limit and BigMath to any precision included, for ruby.wasm and other places without
15
+ a C compiler."
15
16
  email:
16
- - andi@idogawa.com
17
+ - web@idogawa.com
17
18
  executables: []
18
19
  extensions: []
19
20
  extra_rdoc_files: []
@@ -26,6 +27,10 @@ files:
26
27
  - lib/bigdecimal/pure.rb
27
28
  - lib/bigdecimal/util.rb
28
29
  - lib/bigdecimal_pure.rb
30
+ - lib/bigdecimal_pure/calc.rb
31
+ - lib/bigdecimal_pure/decimal.rb
32
+ - lib/bigdecimal_pure/math.rb
33
+ - lib/bigdecimal_pure/util.rb
29
34
  - lib/bigdecimal_pure/version.rb
30
35
  homepage: https://github.com/Largo/bigdecimal-pure
31
36
  licenses: