sanscript 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78a9a4f83c7ebeabdf0a4ce0b02c0efbe2bb99bd
4
- data.tar.gz: 1e16e165ab8587163be05d449301c182d70b8037
3
+ metadata.gz: 80ce63ec01301d3bafb6e0b5b2e407255c8764e3
4
+ data.tar.gz: 2da0b081137b3fa9a286e176adb1eea0a329fae1
5
5
  SHA512:
6
- metadata.gz: 0354c6bb4d13b5aca33b73febb968f72dfaa843a7c6231fc30482f66d04bd8d239250a2aa0f0dbc957e4fef35d46173800319cd8583e8433cb9a1127e192d519
7
- data.tar.gz: f0131f094b3a4e88cb7bba19955c27f1337b4ea7f2d1ca419e5bb8cd61f2546b515f52c2f60b44df1bdc91494f5cd0cb3e9f7a52b4c39b680039db7a23ba6bfb
6
+ metadata.gz: 7d377ccfbc03e784fa18d80b2e65189eb07c76bc012c57224fb12e01712391b511fd5ecb0fd0933545ab25d8c5480fccc0a08cb9adcdc79cecb94ef3168fdcb3
7
+ data.tar.gz: f1f2be9cbc4414d7c284322ba0d8525732436f7d0a80880b6dfaf5076f65f991fe38e143d69b9254327ecb983d7658182ff7b72ec1522745be5a6732af75bb61
data/lib/sanscript.rb CHANGED
@@ -10,13 +10,11 @@ require "sanscript/benchmark"
10
10
 
11
11
  # Sanscript.rb detection/transliteration module for Sanskrit.
12
12
  module Sanscript
13
- # :nocov:
14
- if RUST_AVAILABLE && ENV["SANSCRIPT_NO_RUST"].nil?
15
- rust_enable!
16
- else
17
- rust_disable!
18
- end
19
- # :nocov:
13
+ # Whether Rust extension is available.
14
+ RUST_AVAILABLE = load_rust!
15
+
16
+ # Load rust if available.
17
+ rust_enable!
20
18
 
21
19
  module_function
22
20
 
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # :nocov:
4
- begin
5
- require "benchmark/ips"
6
- rescue LoadError
7
- module Benchmark
8
- def self.ips(*)
9
- raise NotImplementedError, "You must install the `benchmark-ips` gem first."
3
+ module Sanscript
4
+ # :nocov:
5
+ begin
6
+ require "benchmark/ips"
7
+ rescue LoadError
8
+ module ::Benchmark
9
+ def self.ips(*)
10
+ raise NotImplementedError, "You must install the `benchmark-ips` gem first."
11
+ end
10
12
  end
11
13
  end
12
- end
13
- # :nocov:
14
+ # :nocov:
14
15
 
15
- module Sanscript
16
16
  # Benchmark/testing module.
17
17
  module Benchmark
18
18
  module_function
@@ -73,9 +73,5 @@ module Sanscript
73
73
  class << self
74
74
  alias detect_scheme ruby_detect_scheme
75
75
  end
76
-
77
- if defined?(Rust) && Rust.instance_methods.include?(:rust_detect_scheme)
78
- extend Rust
79
- end
80
76
  end
81
77
  end
@@ -3,6 +3,7 @@
3
3
  module Sanscript
4
4
  module Detect
5
5
  # Module implementing `detect_scheme` method using Ruby 2.4's faster Regexp#match? method
6
+ # (Note: This module will only load if chosen by {Sanscript::Detect}.)
6
7
  module Ruby24
7
8
  # Attempts to detect the encoding scheme of the provided string.
8
9
  # Uses Ruby 2.4's Regexp#match? method for additional speed.
@@ -3,6 +3,7 @@
3
3
  module Sanscript
4
4
  module Detect
5
5
  # Module implementing `detect_scheme` method using Ruby 2.x-compatible syntax.
6
+ # (Note: This module will only load if chosen by {Sanscript::Detect}.)
6
7
  module Ruby2x
7
8
  # Attempts to detect the encoding scheme of the provided string.
8
9
  #
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sanscript
4
+ module Detect
5
+ # Module stub for implementing `detect_scheme` method using Rust native extension.
6
+ # (Note: This module will only exist if the native extension is available and {Sanscript.load_rust!} has been run.)
7
+ module Rust
8
+ # @!method rust_detect_scheme(text)
9
+ # Attempts to detect the encoding scheme of the provided string.
10
+ # Uses Rust native extension for vastly increased performance.
11
+ #
12
+ # @param text [String] a string of Sanskrit text
13
+ # @return [Symbol, nil] the Symbol of the scheme, or nil if no match
14
+ end
15
+ end
16
+ end
@@ -1,20 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
  module Sanscript
3
- begin
4
- require "thermite/fiddle"
3
+ module_function
5
4
 
5
+ # Attempts to load Rust native extension.
6
+ # @return [bool] whether the extension loaded.
7
+ def load_rust!
8
+ return RUST_AVAILABLE if defined?(RUST_AVAILABLE)
9
+ require "thermite/fiddle"
6
10
  Thermite::Fiddle.load_module("init_rusty_sanscript",
7
11
  cargo_project_path: GEM_ROOT,
8
12
  ruby_project_path: GEM_ROOT)
9
13
  #:nocov:#
10
- RUST_AVAILABLE = true
14
+ true
11
15
  rescue Fiddle::DLError
12
- RUST_AVAILABLE = false
16
+ false
13
17
  #:nocov:#
14
18
  end
15
19
 
16
- module_function
17
-
18
20
  # @return [bool] the enabled status of the Rust extension
19
21
  def rust_enabled?
20
22
  @rust_enabled
@@ -24,12 +26,16 @@ module Sanscript
24
26
  # @return [bool] the enabled status of the Rust extension
25
27
  def rust_enable!
26
28
  if RUST_AVAILABLE
29
+ # :nocov:
27
30
  Detect.module_eval do
28
31
  class << self
29
32
  alias_method :detect_scheme, :rust_detect_scheme
30
33
  end
31
34
  end
32
35
  @rust_enabled = true
36
+ else
37
+ @rust_enabled = false
38
+ # :nocov:
33
39
  end
34
40
  @rust_enabled
35
41
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Sanscript
3
3
  # The version number
4
- VERSION = "0.7.0"
4
+ VERSION = "0.7.1"
5
5
 
6
6
  GEM_ROOT = Pathname.new(File.realpath(File.join(__dir__, "..", "..")))
7
7
  private_constant :GEM_ROOT
data/src/detect/ruby.rs CHANGED
@@ -39,4 +39,5 @@ pub extern fn init_rusty_sanscript() {
39
39
  let m_rust = rb::define_module_under(&m_detect, "Rust");
40
40
  rb::define_method(&m_rust, "rust_detect_scheme",
41
41
  rbstr_detect_scheme as CallbackPtr, 1);
42
+ rb::extend_object(&m_detect, &m_rust);
42
43
  }
data/src/rb.rs CHANGED
@@ -46,3 +46,7 @@ pub fn define_method(module: &Value, name: &str, method: CallbackPtr, argc: i32)
46
46
  let c_strp = str_to_cstrp(name);
47
47
  unsafe { class::rb_define_method(*module, c_strp, method, argc) }
48
48
  }
49
+
50
+ pub fn extend_object(object: &Value, module: &Value) {
51
+ unsafe { class::rb_extend_object(*object, *module) }
52
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanscript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Bellefleur
@@ -190,6 +190,7 @@ files:
190
190
  - lib/sanscript/detect.rb
191
191
  - lib/sanscript/detect/ruby24.rb
192
192
  - lib/sanscript/detect/ruby2x.rb
193
+ - lib/sanscript/detect/rust.rb
193
194
  - lib/sanscript/exceptions.rb
194
195
  - lib/sanscript/rust.rb
195
196
  - lib/sanscript/transliterate.rb