colordom 0.8.0 → 1.0.0

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: 30e3d2955aeca515a0954b711f27a28a5f56f8209d691cd0a0d62342233a3a4c
4
- data.tar.gz: ab16a833484169dbbfca29b97fe45a37eae9059d594a134adaa94b45d45787c1
3
+ metadata.gz: 94afc63c3c09bdb3a95b46e1addc8cd4b01e789dc5608e9cb7ca7c98d895c3a3
4
+ data.tar.gz: c5d316e57bef0e142773d906f15d84d757b1eddf16016d320859767fee72990c
5
5
  SHA512:
6
- metadata.gz: 1f007efa2d93083c74aec5f37dca696d6e8d7a0dfe6aaf025e905acb0ef3e68ca7040fc9782e804cb69a6134b90fd3e3652f4b4ecfda7738ae83378e55500ae2
7
- data.tar.gz: 7045debdfbcb5bf5e24d012f1bb32124b59345d44a54e171917f849c10d766c0db29f7f85f3a5bf45d21ce932e027595da2f3c15fab42c03d3e685b71f1783c6
6
+ metadata.gz: 5b62978940b5a5fa4278de9c221b25a4a084dbde3db3acec32d5935e6ef1810ff335884c8f37227aca1a0ef59cdf040125d75536e33fb4281e565414142e2650
7
+ data.tar.gz: 1455b29e2c473db6876482c027096b66bb3cdbb7f908ab01bbed2a245487164b2cf8578e80ba11b2ab88c60679506af901c8e324010dc0ab5aa4684ab0762e38
@@ -6,7 +6,7 @@ edition = "2018"
6
6
 
7
7
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8
8
  [dependencies]
9
- magnus = "0.5"
9
+ magnus = "0.7"
10
10
  image = "0.24"
11
11
  dominant_color = "0.3"
12
12
  palette_extract = "0.1"
@@ -1,8 +1,7 @@
1
1
  use std::path::PathBuf;
2
2
 
3
3
  use magnus::{
4
- class, define_module, function, method,
5
- prelude::*, gc::register_mark_object, memoize,
4
+ function, method, prelude::*, value::Lazy, Ruby,
6
5
  Error, ExceptionClass, RModule, IntoValueFromNative
7
6
  };
8
7
 
@@ -10,12 +9,20 @@ use image::{DynamicImage};
10
9
  use palette_extract::{Quality, MaxColors, PixelEncoding, PixelFilter};
11
10
  use palette::{FromColor, IntoColor, Lab, Pixel, Srgb};
12
11
 
12
+ static MODULE: Lazy<RModule> =
13
+ Lazy::new(|ruby| ruby.class_object().const_get("Colordom").unwrap());
14
+
15
+ static ERROR: Lazy<ExceptionClass> =
16
+ Lazy::new(|ruby| ruby.get_inner(&MODULE).const_get("Error").unwrap());
17
+
13
18
  fn colordom_error() -> ExceptionClass {
14
- *memoize!(ExceptionClass: {
15
- let ex = class::object().const_get::<_, RModule>("Colordom").unwrap().const_get("Error").unwrap();
16
- register_mark_object(ex);
17
- ex
18
- })
19
+ Ruby::get().unwrap().get_inner(&ERROR)
20
+ }
21
+
22
+ macro_rules! error {
23
+ ($ex:ident) => {
24
+ Error::new(colordom_error(), $ex.to_string())
25
+ };
19
26
  }
20
27
 
21
28
  #[derive(Clone)]
@@ -58,7 +65,7 @@ impl Image {
58
65
  fn new(path: PathBuf) -> Result<Self, Error> {
59
66
  match image::open(&path) {
60
67
  Ok(img) => Ok(Self { img }),
61
- Err(ex) => Err(Error::new(colordom_error(), ex.to_string()))
68
+ Err(ex) => Err(error!(ex))
62
69
  }
63
70
  }
64
71
 
@@ -123,10 +130,10 @@ impl Image {
123
130
  }
124
131
 
125
132
  #[magnus::init]
126
- fn init() -> Result<(), Error> {
127
- let module = define_module("Colordom")?;
133
+ fn init(ruby: &Ruby) -> Result<(), Error> {
134
+ let module = ruby.define_module("Colordom")?;
128
135
 
129
- let colorc = module.define_class("Color", class::object())?;
136
+ let colorc = module.define_class("Color", ruby.class_object())?;
130
137
 
131
138
  colorc.define_singleton_method("new", function!(Color::new, 3))?;
132
139
  colorc.define_method("r", method!(Color::r, 0))?;
@@ -142,7 +149,7 @@ fn init() -> Result<(), Error> {
142
149
  colorc.define_alias("to_rgb", "rgb")?;
143
150
  colorc.define_alias("to_hex", "hex")?;
144
151
 
145
- let imagec = module.define_class("Image", class::object())?;
152
+ let imagec = module.define_class("Image", ruby.class_object())?;
146
153
 
147
154
  imagec.define_singleton_method("new", function!(Image::new, 1))?;
148
155
  imagec.define_method("histogram", method!(Image::histogram, 1))?;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Colordom
4
- VERSION = '0.8.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colordom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2024-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.4.19
108
+ rubygems_version: 3.5.3
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Extract dominant colors from images