sumi-ruby 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9316b4bb6bf6bef389065fc6c958137747810f368093293951a9e78534ad993
4
+ data.tar.gz: 0d06594b46fe42130c8c352ae33a7893f1fb4ba5c7e7867b18ef2e05638f7676
5
+ SHA512:
6
+ metadata.gz: 4a1728eddcdb67b32ae71ccd191282c81129847b4386b0e5e37142ae33e6581e3732d9d31477f3ead5f02348ef1332e7dfcf134bcb333c661bed29c22efb4c87
7
+ data.tar.gz: 6cd2df269185d77558cf8614c8eb07f9402abfffa446d863b3b634e4dda6458ffccd7b2a26588d074085ca2a37cb1ae057c92ebe441899fd37f56cc16e7fdd46
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Junya Ishihara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # sumi-ruby
2
+
3
+ [sumi](https://github.com/champierre/sumi)(PDF の色をグレースケールや白黒に変換する CLI)のビルド済み実行ファイルを同梱した gem です。
4
+ `bundle install` だけで sumi が入り、`Gemfile.lock` で開発環境・CI・本番のバージョンがそろいます。
5
+
6
+ gem のバージョンは、同梱している sumi のバージョンと同じです。
7
+
8
+ ## インストール
9
+
10
+ ```ruby
11
+ # Gemfile
12
+ gem "sumi-ruby"
13
+ ```
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ ## 使い方
20
+
21
+ ```bash
22
+ bundle exec sumi input.pdf -o output.pdf
23
+ ```
24
+
25
+ Ruby からは `Sumi::Ruby.executable` で実行ファイルの絶対パスを取得できます。
26
+
27
+ ```ruby
28
+ require "open3"
29
+ require "sumi/ruby"
30
+
31
+ _stdout, stderr, status = Open3.capture3(
32
+ Sumi::Ruby.executable, "input.pdf", "-o", "output.pdf", "--report", "json"
33
+ )
34
+ ```
35
+
36
+ オプションや JSON レポートの形式は、[sumi の README](https://github.com/champierre/sumi#cli) を参照してください。
37
+
38
+ ## 対応プラットフォーム
39
+
40
+ | gem のプラットフォーム | 同梱している実行ファイル |
41
+ |---|---|
42
+ | `x86_64-linux-gnu` `x86_64-linux-musl` | `sumi-x86_64-unknown-linux-musl` |
43
+ | `aarch64-linux-gnu` `aarch64-linux-musl` | `sumi-aarch64-unknown-linux-musl` |
44
+ | `x86_64-darwin` | `sumi-x86_64-apple-darwin` |
45
+ | `arm64-darwin` | `sumi-aarch64-apple-darwin` |
46
+ | `x64-mingw-ucrt` | `sumi-x86_64-pc-windows-msvc` |
47
+
48
+ 実行ファイルは [GitHub Releases](https://github.com/champierre/sumi/releases) で配布しているものと同じです。
49
+ Linux 版は静的リンク(musl)なので、glibc の環境でも musl(Alpine など)の環境でも動きます。
50
+ Linux 向けの gem には RubyGems 3.3.22 以降が必要です。Ruby 3.1.3 以降に付属する RubyGems なら満たしています(それより前の Ruby では `gem update --system` で更新してください)。
51
+
52
+ ### `Gemfile.lock` のプラットフォーム
53
+
54
+ Bundler は `Gemfile.lock` の `PLATFORMS` にあるプラットフォームの gem を選びます。
55
+ 開発に使う Mac と本番の Linux のように環境が分かれる場合は、使うプラットフォームを追加しておきます。
56
+
57
+ ```bash
58
+ bundle lock --add-platform x86_64-linux-gnu aarch64-linux-gnu arm64-darwin
59
+ ```
60
+
61
+ `PLATFORMS` に `ruby` しかないと、実行ファイルを含まない gem が入り、実行時にエラーになります。
62
+
63
+ ### 対応していない環境
64
+
65
+ 上の表にない環境では、sumi をソースからビルドし、そのディレクトリを環境変数 `SUMI_INSTALL_DIR` で指定してください。
66
+ `SUMI_INSTALL_DIR` を指定すると、同梱の実行ファイルより優先されます。
67
+
68
+ ```bash
69
+ cargo install --git https://github.com/champierre/sumi sumi-cli
70
+ export SUMI_INSTALL_DIR="$HOME/.cargo/bin"
71
+ ```
72
+
73
+ ## 開発
74
+
75
+ ```bash
76
+ cd ruby
77
+ bundle install
78
+ bundle exec rake test # テスト
79
+ bundle exec rake gem:local # この環境向けの gem を cargo build --release からビルド(pkg/ に出力)
80
+ bundle exec rake gem:release[../dist] # リリースのアーカイブからすべての gem をビルド
81
+ ```
82
+
83
+ ## ライセンス
84
+
85
+ [MIT](https://github.com/champierre/sumi/blob/main/LICENSE)
data/exe/sumi ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Runs the sumi executable bundled with the sumi-ruby gem, passing all arguments through.
5
+
6
+ require "sumi/ruby"
7
+
8
+ begin
9
+ executable = Sumi::Ruby.executable
10
+ rescue Sumi::Ruby::Error => e
11
+ warn "sumi-ruby: #{e.message}"
12
+ exit 1
13
+ end
14
+
15
+ exec(executable, *ARGV)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sumi
4
+ module Ruby
5
+ # Gem platforms with a native gem, and the Rust target whose release archive supplies the
6
+ # executable. The Linux executables are statically linked against musl, so the same binary
7
+ # runs on both glibc and musl systems.
8
+ PLATFORMS = {
9
+ "x86_64-linux-gnu" => "x86_64-unknown-linux-musl",
10
+ "x86_64-linux-musl" => "x86_64-unknown-linux-musl",
11
+ "aarch64-linux-gnu" => "aarch64-unknown-linux-musl",
12
+ "aarch64-linux-musl" => "aarch64-unknown-linux-musl",
13
+ "x86_64-darwin" => "x86_64-apple-darwin",
14
+ "arm64-darwin" => "aarch64-apple-darwin",
15
+ "x64-mingw-ucrt" => "x86_64-pc-windows-msvc"
16
+ }.freeze
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sumi
4
+ module Ruby
5
+ # Always the same as the version of the bundled sumi CLI (`Cargo.toml`).
6
+ VERSION = "0.2.0"
7
+ end
8
+ end
data/lib/sumi/ruby.rb ADDED
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby/version"
4
+ require_relative "ruby/platforms"
5
+
6
+ module Sumi
7
+ module Ruby
8
+ class Error < StandardError; end
9
+ class UnsupportedPlatformError < Error; end
10
+ class ExecutableNotFoundError < Error; end
11
+ class DirectoryNotFoundError < Error; end
12
+
13
+ GEM_NAME = "sumi-ruby"
14
+ INSTALL_DIR_ENV = "SUMI_INSTALL_DIR"
15
+ DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe"))
16
+
17
+ class << self
18
+ # Returns the absolute path of the sumi executable.
19
+ #
20
+ # Native gems carry the executable in `exe/<platform>/`. Setting `SUMI_INSTALL_DIR` to a
21
+ # directory that contains `sumi` (or `sumi.exe`) uses that executable instead, for
22
+ # example on a platform without a native gem.
23
+ def executable(exe_path: DEFAULT_DIR)
24
+ install_dir = ENV[INSTALL_DIR_ENV]
25
+ if install_dir && !install_dir.empty?
26
+ unless File.directory?(install_dir)
27
+ raise DirectoryNotFoundError, "#{INSTALL_DIR_ENV} is set to #{install_dir}, but that directory does not exist"
28
+ end
29
+
30
+ file = executable_in(File.expand_path(install_dir))
31
+ return file if file
32
+
33
+ raise ExecutableNotFoundError, "#{INSTALL_DIR_ENV} is set to #{install_dir}, but it does not contain a sumi executable"
34
+ end
35
+
36
+ file = Dir.glob(File.join(exe_path, "*")).sort.find do |dir|
37
+ File.directory?(dir) && platform_matches?(File.basename(dir)) && executable_in(dir)
38
+ end
39
+ return executable_in(file) if file
40
+
41
+ platform = PLATFORMS.keys.find { |name| platform_matches?(name) }
42
+ unless platform
43
+ raise UnsupportedPlatformError, <<~MESSAGE
44
+ #{GEM_NAME} does not ship a sumi executable for #{Gem::Platform.local}.
45
+ Supported platforms: #{PLATFORMS.keys.join(", ")}.
46
+ Build sumi from source (https://github.com/champierre/sumi) and set #{INSTALL_DIR_ENV} to the directory that contains it.
47
+ MESSAGE
48
+ end
49
+
50
+ raise ExecutableNotFoundError, <<~MESSAGE
51
+ Cannot find the sumi executable for #{Gem::Platform.local} in #{exe_path}.
52
+ Bundler may have installed the platform-independent #{GEM_NAME} gem. Add the platform to the lockfile and install again:
53
+ bundle lock --add-platform #{platform}
54
+ bundle install
55
+ Or set #{INSTALL_DIR_ENV} to a directory that contains the sumi executable.
56
+ MESSAGE
57
+ end
58
+
59
+ private
60
+
61
+ def executable_in(dir)
62
+ ["sumi", "sumi.exe"]
63
+ .map { |name| File.join(dir, name) }
64
+ .find { |path| File.file?(path) && File.executable?(path) }
65
+ end
66
+
67
+ def platform_matches?(name)
68
+ Gem::Platform.match_gem?(Gem::Platform.new(name), GEM_NAME)
69
+ end
70
+ end
71
+ end
72
+ end
data/lib/sumi-ruby.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Lets `Bundler.require` load the gem by its name.
4
+ require_relative "sumi/ruby"
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sumi-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Junya Ishihara
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ Ships the prebuilt sumi executable for each platform, so that `bundle install` installs the
14
+ same version of sumi in development, CI and production. sumi converts the colors of a PDF
15
+ to grayscale or monochrome while keeping text and vector graphics.
16
+ executables:
17
+ - sumi
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - exe/sumi
24
+ - lib/sumi-ruby.rb
25
+ - lib/sumi/ruby.rb
26
+ - lib/sumi/ruby/platforms.rb
27
+ - lib/sumi/ruby/version.rb
28
+ homepage: https://github.com/champierre/sumi
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ homepage_uri: https://github.com/champierre/sumi
33
+ source_code_uri: https://github.com/champierre/sumi/tree/main/ruby
34
+ changelog_uri: https://github.com/champierre/sumi/releases
35
+ bug_tracker_uri: https://github.com/champierre/sumi/issues
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.1'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.6.9
51
+ specification_version: 4
52
+ summary: The sumi CLI, which converts PDFs to grayscale or monochrome, packaged as
53
+ a gem
54
+ test_files: []