twips 0.11.3.pre.dev

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c18541fb2b07353ba3d3ee6ee802524e9001b88d0efea12c3b8730bb6f56691b
4
+ data.tar.gz: ccf9e79ea763c4c1ccd2893f67c17f13787038f5733ebb239ef8844e9afa1d67
5
+ SHA512:
6
+ metadata.gz: 580e1d4e37f8413e8412ad1569bfe5e6886ba8e162a35eee2a0f3bb57c7803503e277b484b6e2e6314771c3178c4dfb14afbe58e63c81c377b16bfdc2af3fc42
7
+ data.tar.gz: 83f8041e97e16d7345ef765fc061b6c87803c3cb4b23bf62548be09205d8f5d6cf23f58a1fb278b61d8e6399c11ea35813a7b9a2c5559d835c10fea3cc0858c7
@@ -0,0 +1,13 @@
1
+ [package]
2
+ name = "twips-rb"
3
+ version.workspace = true
4
+ license.workspace = true
5
+ edition.workspace = true
6
+ publish = false
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ magnus = { version = "0.8.2" }
13
+ twips = { path = "../../../lib" }
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ # https://github.com/oxidize-rb/rb-sys/tree/main/gem
7
+ create_rust_makefile("twips/twips_rb")
@@ -0,0 +1,75 @@
1
+ use std::str::FromStr;
2
+
3
+ use magnus::{function, prelude::*, Error, Ruby};
4
+
5
+ use twips::scramble::{
6
+ derive_scramble_for_event_seeded, random_scramble_for_event,
7
+ scramble_finder::free_memory_for_all_scramble_finders, DerivationSalt, DerivationSeed, Event,
8
+ };
9
+
10
+ fn rb_random_scramble_for_event(ruby: &Ruby, event_str: String) -> Result<String, Error> {
11
+ let event = Event::try_from(event_str.as_str())
12
+ .map_err(|e| Error::new(ruby.exception_arg_error(), e.description))?;
13
+
14
+ random_scramble_for_event(event)
15
+ .map(|scramble| scramble.to_string())
16
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), e.description))
17
+ }
18
+
19
+ fn rb_derive_scramble_for_event(
20
+ ruby: &Ruby,
21
+ hex_derivation_seed_str: String,
22
+ derivation_salt_hierarchy_str: Vec<String>,
23
+ subevent_str: String,
24
+ ) -> Result<String, Error> {
25
+ let subevent = Event::try_from(subevent_str.as_str())
26
+ .map_err(|e| Error::new(ruby.exception_arg_error(), e.description))?;
27
+
28
+ let derivation_seed = DerivationSeed::from_str(&hex_derivation_seed_str)
29
+ .map_err(|e| Error::new(ruby.exception_arg_error(), e))?;
30
+
31
+ let hierarchy = derivation_salt_hierarchy_str
32
+ .iter()
33
+ .map(|s| s.as_str())
34
+ .map(DerivationSalt::from_str)
35
+ .collect::<Result<Vec<DerivationSalt>, String>>()
36
+ .map_err(|e| Error::new(ruby.exception_arg_error(), e))?;
37
+
38
+ derive_scramble_for_event_seeded(&derivation_seed, &hierarchy, subevent)
39
+ .map(|scramble| scramble.to_string())
40
+ .map_err(|e| Error::new(ruby.exception_runtime_error(), e))
41
+ }
42
+
43
+ fn rb_free_memory_for_all_scramble_finders() -> usize {
44
+ free_memory_for_all_scramble_finders()
45
+ }
46
+
47
+ #[magnus::init]
48
+ fn init(ruby: &Ruby) -> Result<(), Error> {
49
+ let module = ruby.define_module("Twips")?;
50
+
51
+ module.define_singleton_method(
52
+ "random_scramble_for_event",
53
+ function!(rb_random_scramble_for_event, 1),
54
+ )?;
55
+
56
+ module.define_singleton_method(
57
+ "derive_scramble_for_event",
58
+ function!(rb_derive_scramble_for_event, 3),
59
+ )?;
60
+
61
+ module.define_singleton_method(
62
+ "free_memory_for_all_scramble_finders",
63
+ function!(rb_free_memory_for_all_scramble_finders, 0),
64
+ )?;
65
+
66
+ Ok(())
67
+ }
68
+
69
+ #[cfg(test)]
70
+ mod tests {
71
+ #[test]
72
+ fn stub_test() -> Result<(), String> {
73
+ Ok(())
74
+ }
75
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twips
4
+ VERSION = "0.11.3-dev"
5
+ end
data/lib/twips.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "twips/version"
4
+ require_relative "twips/twips_rb"
5
+
6
+ ##
7
+ # Top level module.
8
+ #
9
+ # Methods defined in ext/twips/src/lib.rs
10
+ #
11
+ # Ex Twips.random_scramble_for_event(event_id) => String
12
+ #
13
+ module Twips
14
+ end
data/sig/twips.rbs ADDED
@@ -0,0 +1,7 @@
1
+ module Twips
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+
5
+ def self.random_scramble_for_event: (String) -> String
6
+ def self.derive_scramble_for_event: (String, String, String) -> String
7
+ end
data/twips.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/twips/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "twips"
7
+ spec.version = Twips::VERSION
8
+ spec.authors = ["Lucas Garron", "Tom Rokicki", "Gregor Billing"]
9
+
10
+ spec.summary = "Ruby scramble generation using twips"
11
+ spec.description = "Ruby scramble generation using twips."
12
+ spec.homepage = "https://github.com/cubing/twips"
13
+ spec.required_ruby_version = ">= 3.0.0"
14
+ spec.required_rubygems_version = ">= 3.4.6"
15
+
16
+ spec.metadata["bug_tracker_uri"] = "https://github.com/cubing/twips/issues"
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/cubing/twips"
19
+
20
+ spec.files = Dir["ext/**/*"] +
21
+ Dir["lib/**/*.rb"] +
22
+ Dir["sig/twips.rbs"] +
23
+ Dir["twips.gemspec"]
24
+ spec.require_paths = ["lib"]
25
+ spec.extensions = ["ext/twips/extconf.rb"]
26
+
27
+ spec.metadata["rubygems_mfa_required"] = "true"
28
+
29
+ spec.add_dependency("rb_sys", "~> 0.9.117")
30
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twips
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.3.pre.dev
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Garron
8
+ - Tom Rokicki
9
+ - Gregor Billing
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 1980-01-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rb_sys
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.9.117
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.117
28
+ description: Ruby scramble generation using twips.
29
+ executables: []
30
+ extensions:
31
+ - ext/twips/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ext/twips/Cargo.toml
35
+ - ext/twips/extconf.rb
36
+ - ext/twips/src/lib.rs
37
+ - lib/twips.rb
38
+ - lib/twips/version.rb
39
+ - sig/twips.rbs
40
+ - twips.gemspec
41
+ homepage: https://github.com/cubing/twips
42
+ licenses: []
43
+ metadata:
44
+ bug_tracker_uri: https://github.com/cubing/twips/issues
45
+ homepage_uri: https://github.com/cubing/twips
46
+ source_code_uri: https://github.com/cubing/twips
47
+ rubygems_mfa_required: 'true'
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.0.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.4.6
61
+ requirements: []
62
+ rubygems_version: 3.6.9
63
+ specification_version: 4
64
+ summary: Ruby scramble generation using twips
65
+ test_files: []