cinnabar 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6647629512489671373fd91ffdd165fcdc08306caad030e7ad827adefb070bf5
4
+ data.tar.gz: 24e45eca6665b1a715dc9b7cd58547b6e6bb4ffbc1777a6250c8d55f537acaed
5
+ SHA512:
6
+ metadata.gz: 9de983869bf035c25dcadaab1f4b803a46e2dabc48e1d5bfe42ca4314006f9b13f1aa7bebb37fbbfb226c266fd0689dec57b15c0957735137349e9b9b0bf2a79
7
+ data.tar.gz: 53d3feb704e7004cb4ba194854186a543fe0d42a9fca1abe5a689aba9464bac1ad7d6f30cdd83214710dd6543a1a2be260b3ea6568d459ea5b6bfa77358a6cc4
data/.rubocop.yml ADDED
@@ -0,0 +1,45 @@
1
+ # ln ~/.config/rubocop/config.yml .rubocop.yml
2
+ AllCops:
3
+ TargetRubyVersion: 3.1
4
+
5
+ Lint/MissingCopEnableDirective:
6
+ Enabled: false
7
+ Lint/RedundantCopDisableDirective:
8
+ Enabled: false
9
+ Lint/EmptyExpression:
10
+ # disabled => allow ()
11
+ Enabled: false
12
+
13
+ # https://docs.rubocop.org/rubocop/cops_style.html
14
+ Style/TrailingCommaInHashLiteral:
15
+ EnforcedStyleForMultiline: diff_comma
16
+ Style/TrailingCommaInArrayLiteral:
17
+ EnforcedStyleForMultiline: diff_comma
18
+ Style/Lambda:
19
+ EnforcedStyle: literal
20
+ Style/ModuleFunction:
21
+ # EnforcedStyle: extend_self
22
+ EnforcedStyle: module_function
23
+ Style/BlockDelimiters:
24
+ EnforcedStyle: braces_for_chaining
25
+ Style/Documentation:
26
+ Enabled: false
27
+ Style/ClassAndModuleChildren:
28
+ EnforcedStyle: compact
29
+
30
+ # https://docs.rubocop.org/rubocop/cops_metrics.html
31
+ Metrics/MethodLength:
32
+ Max: 15
33
+
34
+ # https://docs.rubocop.org/rubocop/cops_layout.html
35
+ Layout/CaseIndentation:
36
+ EnforcedStyle: end
37
+ IndentOneStep: true
38
+ Layout/MultilineMethodCallIndentation:
39
+ EnforcedStyle: indented_relative_to_receiver
40
+
41
+
42
+ Naming/AsciiIdentifiers:
43
+ # AsciiConstants: false
44
+ Enabled: false
45
+
data/License ADDED
@@ -0,0 +1,205 @@
1
+ Apache License Version 2.0
2
+
3
+ Copyright (c) 2025 Moe
4
+
5
+ Apache License
6
+ Version 2.0, January 2004
7
+ http://www.apache.org/licenses/
8
+
9
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
10
+
11
+ 1. Definitions.
12
+
13
+ "License" shall mean the terms and conditions for use, reproduction,
14
+ and distribution as defined by Sections 1 through 9 of this document.
15
+
16
+ "Licensor" shall mean the copyright owner or entity authorized by
17
+ the copyright owner that is granting the License.
18
+
19
+ "Legal Entity" shall mean the union of the acting entity and all
20
+ other entities that control, are controlled by, or are under common
21
+ control with that entity. For the purposes of this definition,
22
+ "control" means (i) the power, direct or indirect, to cause the
23
+ direction or management of such entity, whether by contract or
24
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
25
+ outstanding shares, or (iii) beneficial ownership of such entity.
26
+
27
+ "You" (or "Your") shall mean an individual or Legal Entity
28
+ exercising permissions granted by this License.
29
+
30
+ "Source" form shall mean the preferred form for making modifications,
31
+ including but not limited to software source code, documentation
32
+ source, and configuration files.
33
+
34
+ "Object" form shall mean any form resulting from mechanical
35
+ transformation or translation of a Source form, including but
36
+ not limited to compiled object code, generated documentation,
37
+ and conversions to other media types.
38
+
39
+ "Work" shall mean the work of authorship, whether in Source or
40
+ Object form, made available under the License, as indicated by a
41
+ copyright notice that is included in or attached to the work
42
+ (an example is provided in the Appendix below).
43
+
44
+ "Derivative Works" shall mean any work, whether in Source or Object
45
+ form, that is based on (or derived from) the Work and for which the
46
+ editorial revisions, annotations, elaborations, or other modifications
47
+ represent, as a whole, an original work of authorship. For the purposes
48
+ of this License, Derivative Works shall not include works that remain
49
+ separable from, or merely link (or bind by name) to the interfaces of,
50
+ the Work and Derivative Works thereof.
51
+
52
+ "Contribution" shall mean any work of authorship, including
53
+ the original version of the Work and any modifications or additions
54
+ to that Work or Derivative Works thereof, that is intentionally
55
+ submitted to Licensor for inclusion in the Work by the copyright owner
56
+ or by an individual or Legal Entity authorized to submit on behalf of
57
+ the copyright owner. For the purposes of this definition, "submitted"
58
+ means any form of electronic, verbal, or written communication sent
59
+ to the Licensor or its representatives, including but not limited to
60
+ communication on electronic mailing lists, source code control systems,
61
+ and issue tracking systems that are managed by, or on behalf of, the
62
+ Licensor for the purpose of discussing and improving the Work, but
63
+ excluding communication that is conspicuously marked or otherwise
64
+ designated in writing by the copyright owner as "Not a Contribution."
65
+
66
+ "Contributor" shall mean Licensor and any individual or Legal Entity
67
+ on behalf of whom a Contribution has been received by Licensor and
68
+ subsequently incorporated within the Work.
69
+
70
+ 2. Grant of Copyright License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ copyright license to reproduce, prepare Derivative Works of,
74
+ publicly display, publicly perform, sublicense, and distribute the
75
+ Work and such Derivative Works in Source or Object form.
76
+
77
+ 3. Grant of Patent License. Subject to the terms and conditions of
78
+ this License, each Contributor hereby grants to You a perpetual,
79
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
80
+ (except as stated in this section) patent license to make, have made,
81
+ use, offer to sell, sell, import, and otherwise transfer the Work,
82
+ where such license applies only to those patent claims licensable
83
+ by such Contributor that are necessarily infringed by their
84
+ Contribution(s) alone or by combination of their Contribution(s)
85
+ with the Work to which such Contribution(s) was submitted. If You
86
+ institute patent litigation against any entity (including a
87
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
88
+ or a Contribution incorporated within the Work constitutes direct
89
+ or contributory patent infringement, then any patent licenses
90
+ granted to You under this License for that Work shall terminate
91
+ as of the date such litigation is filed.
92
+
93
+ 4. Redistribution. You may reproduce and distribute copies of the
94
+ Work or Derivative Works thereof in any medium, with or without
95
+ modifications, and in Source or Object form, provided that You
96
+ meet the following conditions:
97
+
98
+ (a) You must give any other recipients of the Work or
99
+ Derivative Works a copy of this License; and
100
+
101
+ (b) You must cause any modified files to carry prominent notices
102
+ stating that You changed the files; and
103
+
104
+ (c) You must retain, in the Source form of any Derivative Works
105
+ that You distribute, all copyright, patent, trademark, and
106
+ attribution notices from the Source form of the Work,
107
+ excluding those notices that do not pertain to any part of
108
+ the Derivative Works; and
109
+
110
+ (d) If the Work includes a "NOTICE" text file as part of its
111
+ distribution, then any Derivative Works that You distribute must
112
+ include a readable copy of the attribution notices contained
113
+ within such NOTICE file, excluding those notices that do not
114
+ pertain to any part of the Derivative Works, in at least one
115
+ of the following places: within a NOTICE text file distributed
116
+ as part of the Derivative Works; within the Source form or
117
+ documentation, if provided along with the Derivative Works; or,
118
+ within a display generated by the Derivative Works, if and
119
+ wherever such third-party notices normally appear. The contents
120
+ of the NOTICE file are for informational purposes only and
121
+ do not modify the License. You may add Your own attribution
122
+ notices within Derivative Works that You distribute, alongside
123
+ or as an addendum to the NOTICE text from the Work, provided
124
+ that such additional attribution notices cannot be construed
125
+ as modifying the License.
126
+
127
+ You may add Your own copyright statement to Your modifications and
128
+ may provide additional or different license terms and conditions
129
+ for use, reproduction, or distribution of Your modifications, or
130
+ for any such Derivative Works as a whole, provided Your use,
131
+ reproduction, and distribution of the Work otherwise complies with
132
+ the conditions stated in this License.
133
+
134
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
135
+ any Contribution intentionally submitted for inclusion in the Work
136
+ by You to the Licensor shall be under the terms and conditions of
137
+ this License, without any additional terms or conditions.
138
+ Notwithstanding the above, nothing herein shall supersede or modify
139
+ the terms of any separate license agreement you may have executed
140
+ with Licensor regarding such Contributions.
141
+
142
+ 6. Trademarks. This License does not grant permission to use the trade
143
+ names, trademarks, service marks, or product names of the Licensor,
144
+ except as required for reasonable and customary use in describing the
145
+ origin of the Work and reproducing the content of the NOTICE file.
146
+
147
+ 7. Disclaimer of Warranty. Unless required by applicable law or
148
+ agreed to in writing, Licensor provides the Work (and each
149
+ Contributor provides its Contributions) on an "AS IS" BASIS,
150
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
151
+ implied, including, without limitation, any warranties or conditions
152
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
153
+ PARTICULAR PURPOSE. You are solely responsible for determining the
154
+ appropriateness of using or redistributing the Work and assume any
155
+ risks associated with Your exercise of permissions under this License.
156
+
157
+ 8. Limitation of Liability. In no event and under no legal theory,
158
+ whether in tort (including negligence), contract, or otherwise,
159
+ unless required by applicable law (such as deliberate and grossly
160
+ negligent acts) or agreed to in writing, shall any Contributor be
161
+ liable to You for damages, including any direct, indirect, special,
162
+ incidental, or consequential damages of any character arising as a
163
+ result of this License or out of the use or inability to use the
164
+ Work (including but not limited to damages for loss of goodwill,
165
+ work stoppage, computer failure or malfunction, or any and all
166
+ other commercial damages or losses), even if such Contributor
167
+ has been advised of the possibility of such damages.
168
+
169
+ 9. Accepting Warranty or Additional Liability. While redistributing
170
+ the Work or Derivative Works thereof, You may choose to offer,
171
+ and charge a fee for, acceptance of support, warranty, indemnity,
172
+ or other liability obligations and/or rights consistent with this
173
+ License. However, in accepting such obligations, You may act only
174
+ on Your own behalf and on Your sole responsibility, not on behalf
175
+ of any other Contributor, and only if You agree to indemnify,
176
+ defend, and hold each Contributor harmless for any liability
177
+ incurred by, or claims asserted against, such Contributor by reason
178
+ of your accepting any such warranty or additional liability.
179
+
180
+ END OF TERMS AND CONDITIONS
181
+
182
+ APPENDIX: How to apply the Apache License to your work.
183
+
184
+ To apply the Apache License to your work, attach the following
185
+ boilerplate notice, with the fields enclosed by brackets "[]"
186
+ replaced with your own identifying information. (Don't include
187
+ the brackets!) The text should be enclosed in the appropriate
188
+ comment syntax for the file format. We also recommend that a
189
+ file or class name and description of purpose be included on the
190
+ same "printed page" as the copyright notice for easier
191
+ identification within third-party archives.
192
+
193
+ Copyright [yyyy] [name of copyright owner]
194
+
195
+ Licensed under the Apache License, Version 2.0 (the "License");
196
+ you may not use this file except in compliance with the License.
197
+ You may obtain a copy of the License at
198
+
199
+ http://www.apache.org/licenses/LICENSE-2.0
200
+
201
+ Unless required by applicable law or agreed to in writing, software
202
+ distributed under the License is distributed on an "AS IS" BASIS,
203
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
204
+ See the License for the specific language governing permissions and
205
+ limitations under the License.
data/docs/Readme-zh.md ADDED
@@ -0,0 +1,64 @@
1
+ # Cinnabar
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cinnabar.svg?icon=si%3Arubygems)](https://rubygems.org/gems/cinnabar)
4
+
5
+ 专为 CI 流程打造的工具集。
6
+
7
+ ---
8
+
9
+ | Language/語言 | ID |
10
+ | ------------------------------- | ---------- |
11
+ | 简体中文 | zh-Hans-CN |
12
+ | [English](./Readme.md) | en-Latn-US |
13
+ | [繁體中文](./Readme-zh-Hant.md) | zh-Hant-TW |
14
+
15
+ ---
16
+
17
+ ## 前言
18
+
19
+ **问:为何取名为 Cinnabar(朱砂)?**
20
+
21
+ **答:**
22
+
23
+ 1. 朱砂是中国古代道教炼丹师在炼丹时使用的一种原料,就像这个项目在 CI 工作流中充当一种“原料”。
24
+ 2. 朱砂有毒。这个项目是为了 **猛、糙、快** (a.k.a. *Dirty and Quick*) 的目的而开发的,可能会产生意料之外的副作用(它并非完全无害)。
25
+ 3. 朱砂是一种硫化汞 (HgS) 的矿物,呈深红色,而 Ruby 也是一种深红色的宝石。给一个 Ruby 项目取名为 “Cinnabar(朱砂)” 非常贴切。
26
+
27
+ ## 快速上手
28
+
29
+ Github Actions for cinnabar
30
+
31
+ ```yaml
32
+ env:
33
+ # Speeds up script startup by disabling RubyGems
34
+ RUBYOPT: "--disable=gems"
35
+ default_ci_shell: ruby cinnabar/ci.rb {0}
36
+
37
+ jobs:
38
+ build:
39
+ runs-on: ubuntu-latest
40
+ defaults:
41
+ run:
42
+ shell: ${{env.default_ci_shell}}
43
+ steps:
44
+ - uses: actions/checkout@v6
45
+
46
+ - name: clone cinnabar
47
+ uses: actions/checkout@v6
48
+ with:
49
+ repository: 2moe/cinnabar
50
+ path: cinnabar
51
+ ref: v0.0.0
52
+
53
+ - name: (example) run cargo command
54
+ run: |
55
+ {
56
+ cargo: (),
57
+ build: (),
58
+ profile: 'release',
59
+ verbose: true,
60
+ target: 'x86_64-unknown-linux-musl'
61
+ }
62
+ .to_argv
63
+ .run
64
+ ```
data/docs/Readme.md ADDED
@@ -0,0 +1,64 @@
1
+ # Cinnabar
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cinnabar.svg?icon=si%3Arubygems)](https://rubygems.org/gems/cinnabar)
4
+
5
+ A handy toolkit tailored for CI workflows.
6
+
7
+ ---
8
+
9
+ | Language/語言 | ID |
10
+ | ------------------------------- | ---------- |
11
+ | English | en-Latn-US |
12
+ | [简体中文](./Readme-zh.md) | zh-Hans-CN |
13
+ | [繁體中文](./Readme-zh-Hant.md) | zh-Hant-TW |
14
+
15
+ ---
16
+
17
+ ## Preface
18
+
19
+ Q: Why is it named Cinnabar?
20
+
21
+ A:
22
+
23
+ 1. Cinnabar was an ingredient used by ancient Daoist alchemists in their elixirs, much like this project serves as an "ingredient" within CI workflows.
24
+ 2. Cinnabar is toxic. This project was developed for *Dirty and Quick* purposes and may produce unexpected side effects—in a sense, it is not entirely harmless.
25
+ 3. Cinnabar, a mineral form of mercury sulfide (HgS), is a deep red-colored stone. And ruby is also a deep red stone. Naming a Ruby project "Cinnabar" is particularly fitting.
26
+
27
+ ## Quick Start
28
+
29
+ Github Actions for cinnabar
30
+
31
+ ```yaml
32
+ env:
33
+ # Speeds up script startup by disabling RubyGems
34
+ RUBYOPT: "--disable=gems"
35
+ default_ci_shell: ruby cinnabar/ci.rb {0}
36
+
37
+ jobs:
38
+ build:
39
+ runs-on: ubuntu-latest
40
+ defaults:
41
+ run:
42
+ shell: ${{env.default_ci_shell}}
43
+ steps:
44
+ - uses: actions/checkout@v6
45
+
46
+ - name: clone cinnabar
47
+ uses: actions/checkout@v6
48
+ with:
49
+ repository: 2moe/cinnabar
50
+ path: cinnabar
51
+ ref: v0.0.0
52
+
53
+ - name: (example) run cargo command
54
+ run: |
55
+ {
56
+ cargo: (),
57
+ build: (),
58
+ profile: 'release',
59
+ verbose: true,
60
+ target: 'x86_64-unknown-linux-musl'
61
+ }
62
+ .to_argv
63
+ .run
64
+ ```
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Define Cinnabar first to prevent errors when creating Cinnabar::SubMod
4
+ # (compact ClassAndModuleChildren)
5
+ #
6
+ # ------------------
7
+
8
+ module Cinnabar; end
9
+
10
+ # To ensure compatibility with "--disable=gems" (allowing users to pre-require),
11
+ # add conditional checks before requiring these libraries.
12
+ require 'sinlog' unless defined? Sinlog::VERSION
13
+ # require 'argvise' unless defined? Argvise::VERSION
14
+
15
+ require 'pathname'
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinnabar::Command
4
+ module_function
5
+
6
+ using Sinlog::Refin
7
+
8
+ # This lambda function is capable of running system command.
9
+ #
10
+ # = Example
11
+ #
12
+ # using Cinnabar::FnPipe::Refin
13
+ #
14
+ # Cmd = Cinnabar::Command
15
+ # %w[sleep 3].▷ Cmd.run
16
+ def run
17
+ ->(array) do
18
+ 'Running system cmd'.log_dbg
19
+ array.log_info
20
+ success = system(*array)
21
+ Kernel.raise "Command failed: #{array.join(' ')}" unless success
22
+ end
23
+ end
24
+
25
+ # Lambda that runs system command in the background.
26
+ #
27
+ # @raise [RuntimeError] if the process exits with non-zero status
28
+ #
29
+ # = Example
30
+ #
31
+ # Cmd = Cinnabar::Command
32
+ # pid = %w[sleep 5].then(&Cmd.run_in_bg)
33
+ def run_in_bg
34
+ ->(array) do
35
+ 'Running system cmd in the background'.log_dbg
36
+ array.log_info
37
+ Process.spawn(*array)
38
+ end
39
+ end
40
+
41
+ # ---------------
42
+
43
+ # Lambda that waits for a child process to complete and checks its status.
44
+ #
45
+ # This method requires the child process to exit with a successful status;
46
+ # otherwise, it will raise an error.
47
+ #
48
+ # = Example
49
+ #
50
+ # using Cinnabar::FnPipe::Refin
51
+ #
52
+ # Cmd = Cinnabar::Command
53
+ # %w[sleep 3]
54
+ # .▷(Cmd.run_in_bg) #=> pid
55
+ # .▷(Cmd.wait_task)
56
+ #
57
+ def wait_task
58
+ ->(pid) do
59
+ "wait pid: #{pid}".log_dbg
60
+ Process.wait(pid)
61
+ status = $? # rubocop:disable Style/SpecialGlobalVars
62
+ "child_status: #{status}".log_dbg
63
+ Kernel.raise %(Command failed with "#{status}") unless status.success?
64
+ end
65
+ end
66
+ # ---------------
67
+ end
68
+
69
+ module Cinnabar::Command
70
+ module ArrayExt
71
+ def run
72
+ Cinnabar::Command.run.call(self)
73
+ end
74
+
75
+ # Spawns system command (runs in the background)
76
+ def run_in_bg
77
+ Cinnabar::Command.run_in_bg.call(self)
78
+ end
79
+ end
80
+
81
+ # ---------------------
82
+
83
+ # monkey patching: Array#run, Array#run_in_bg
84
+ #
85
+ # == Example
86
+ #
87
+ # include Cinnabar::Command::ArrMixin
88
+ #
89
+ # %w[ls -l].run
90
+ #
91
+ # pid = %w[sleep 3].run_in_bg
92
+ module ArrMixin
93
+ def self.included(_host) = ::Array.include ArrayExt
94
+ end
95
+
96
+ # Refinements: Array#run, Array#run_in_bg
97
+ #
98
+ # = Examples
99
+ #
100
+ # == Simple
101
+ #
102
+ # using Cinnabar::Command::ArrRefin
103
+ #
104
+ # %w[ls -l].run
105
+ # #=> execute system('ls', '-l')
106
+ #
107
+ # == Argvise + run_in_bg
108
+ #
109
+ # using Cinnabar::Command::ArrRefin
110
+ # using Argvise::HashRefin
111
+ #
112
+ # pid = {
113
+ # cargo: (),
114
+ # run: (),
115
+ # target: "wasm32-wasip2"
116
+ # }.to_argv.run_in_bg
117
+ # #=> execute Process.spawn('cargo', 'run', '--target', 'wasm32-wasip2')
118
+ #
119
+ module ArrRefin
120
+ refine ::Array do
121
+ import_methods ArrayExt
122
+ end
123
+ end
124
+ end
125
+
126
+ module Cinnabar::Command
127
+ module IntegerExt
128
+ def wait_task
129
+ Cinnabar::Command.wait_task.call(self)
130
+ end
131
+ end
132
+
133
+ # ---------------------
134
+
135
+ # Monkey Patching: Integer#wait_task
136
+ #
137
+ # == Example
138
+ #
139
+ # include Cinnabar::Command::IntMixin
140
+ #
141
+ # pid = %w[sleep 3].run_in_bg
142
+ # p "wait 3s"
143
+ # pid.wait_task
144
+ module IntMixin
145
+ def self.included(_host) = ::Integer.include IntegerExt
146
+ end
147
+
148
+ # Refinement: Integer#wait_task
149
+ #
150
+ # == Example
151
+ #
152
+ # using Cinnabar::Command::IntRefin
153
+ #
154
+ # pid = %w[sleep 3].run_in_bg
155
+ # p "wait 3s"
156
+ # pid.wait_task
157
+ module IntRefin
158
+ refine ::Integer do
159
+ import_methods IntegerExt
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinnabar::Downloader
4
+ module_function
5
+
6
+ require 'open-uri'
7
+
8
+ # == Example
9
+ #
10
+ # url = 'https://docs.ruby-lang.org/en/3.4/OpenURI.html'
11
+ # opts = { out_dir: "tmp", file_name: "doc.html" }
12
+ # DL = Cinnabar::Downloader
13
+ # DL.download(url, opts)
14
+ #
15
+ # == Params
16
+ #
17
+ # - url: [String] e.g., https://url.local
18
+ # - opts: [Hash] e.g., `{out_dir: 'download', file_name: nil, headers: {'User-Agent' => "aria2/1.37.0"}}`
19
+ def download(url, opts)
20
+ out_dir, file_name, headers = opts.values_at(:out_dir, :file_name, :headers)
21
+
22
+ headers = build_headers(headers)
23
+ parsed_url = Kernel.URI(url)
24
+ final_file_name = determine_filename(file_name, parsed_url)
25
+ file_path = setup_file_path(out_dir, final_file_name)
26
+
27
+ Kernel.p file_path
28
+ parsed_url
29
+ .open(headers)
30
+ .then { IO.copy_stream(_1, file_path.to_s) }
31
+ end
32
+
33
+ # => ::Hash
34
+ def build_headers(headers)
35
+ base_headers = {
36
+ 'User-Agent' => 'Mozilla/5.0 (Linux; aarch64 Wayland; rv:138.0) Gecko/20100101 Firefox/138.0',
37
+ }
38
+ base_headers.merge(headers || {}).transform_keys(&:to_s)
39
+ end
40
+
41
+ # => ::String
42
+ def determine_filename(file_name, parsed_url)
43
+ filename = file_name || File.basename(parsed_url.path || '')
44
+ case filename.strip
45
+ when '', '/' then 'index.html'
46
+ else filename
47
+ end
48
+ end
49
+
50
+ # => Kernel.Pathname
51
+ def setup_file_path(out_dir, file_name)
52
+ Kernel.Pathname(out_dir)
53
+ .tap(&:mkpath)
54
+ .join(file_name)
55
+ end
56
+ end
57
+
58
+ module Cinnabar::Downloader
59
+ module StringExt
60
+ def download(out_dir: 'tmp', file_name: nil, headers: {})
61
+ Cinnabar::Downloader.download(self, { out_dir:, file_name:, headers: })
62
+ end
63
+ end
64
+
65
+ # -------------
66
+
67
+ # = Example
68
+ #
69
+ # include Cinnabar::Downloader::StrMixin
70
+ #
71
+ # url = 'https://docs.ruby-lang.org'
72
+ #
73
+ # url.download
74
+ # # OR: url.download(out_dir: "tmp", file_name: "custom.html")
75
+ module StrMixin
76
+ def self.included(_host) = ::String.include StringExt
77
+ end
78
+
79
+ # = Example
80
+ #
81
+ # using Cinnabar::Downloader::StrRefin
82
+ #
83
+ # url = 'https://docs.ruby-lang.org/en/master/OpenURI.html'
84
+ #
85
+ # url.download
86
+ # # OR: url.download(out_dir: "/tmp", file_name: "index.html")
87
+ module StrRefin
88
+ refine ::String do
89
+ import_methods StringExt
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinnabar::FnPipe
4
+ module_function
5
+
6
+ def ▷(obj, other) # rubocop:disable Naming/MethodName
7
+ callable =
8
+ case other
9
+ when Proc, Method then other
10
+ when Symbol, String then Kernel.method(other)
11
+ else Kernel.raise ArgumentError, "Unsupported type: #{other.class}"
12
+ end
13
+ callable.call(obj)
14
+ end
15
+
16
+ # alias 》 ▷
17
+ end
18
+
19
+ module Cinnabar::FnPipe
20
+ module ObjectExt
21
+ def ▷(other) # rubocop:disable Naming/MethodName
22
+ Cinnabar::FnPipe.▷(self, other)
23
+ end
24
+ end
25
+
26
+ # -------------
27
+
28
+ # Function Pipe
29
+ #
30
+ # Monkey Patching: Object#▷
31
+ #
32
+ # = Example
33
+ #
34
+ # include Cinnabar::FnPipe::Mixin
35
+ #
36
+ # put_obj = ->s { puts s }
37
+ # 'Foo'.▷(put_obj)
38
+ # #=> Foo
39
+ #
40
+ # 2.▷ :puts
41
+ # #=> 2
42
+ module Mixin
43
+ def self.included(_host) = ::Object.include ObjectExt
44
+ end
45
+
46
+ # Function Pipe
47
+ #
48
+ # Refinement: Object#▷
49
+ #
50
+ # = Example
51
+ #
52
+ # using Cinnabar::FnPipe::Refin
53
+ #
54
+ # put_obj = ->s { puts s }
55
+ # 'Foo'.▷(put_obj)
56
+ # #=> put_obj.call('Foo') => puts 'Foo' => Foo
57
+ #
58
+ # 2.▷ put_obj
59
+ # #=> put_obj.call(2) => puts 2 => 2
60
+ #
61
+ # 'Bar'.▷ :puts
62
+ # #=> method(:puts).call('Bar') => puts 'Bar' => Bar
63
+ #
64
+ module Refin
65
+ refine ::Object do
66
+ import_methods ObjectExt
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cinnabar
4
+ VERSION = '0.0.0'
5
+ end
data/lib/cinnabar.rb ADDED
@@ -0,0 +1,10 @@
1
+ # This file is automatically generated by "https://github.com/2moe/cinnabar/raw/refs/heads/main/misc/utils/99_autogen_cinnabar.rb"
2
+ # Please edit with caution.
3
+ #
4
+ # frozen_string_literal: true
5
+
6
+ require_relative 'cinnabar/00_pre'
7
+ require_relative 'cinnabar/cmd_runner'
8
+ require_relative 'cinnabar/net'
9
+ require_relative 'cinnabar/pipe'
10
+ require_relative 'cinnabar/version'
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinnabar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - 2moe
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: sinlog
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.0.6
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.0.6
26
+ description: A handy toolkit tailored for CI workflows (e.g., GitHub Actions)
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - ".rubocop.yml"
32
+ - License
33
+ - docs/Readme-zh.md
34
+ - docs/Readme.md
35
+ - lib/cinnabar.rb
36
+ - lib/cinnabar/00_pre.rb
37
+ - lib/cinnabar/cmd_runner.rb
38
+ - lib/cinnabar/net.rb
39
+ - lib/cinnabar/pipe.rb
40
+ - lib/cinnabar/version.rb
41
+ homepage: https://github.com/2moe/cinnabar
42
+ licenses:
43
+ - Apache-2.0
44
+ metadata:
45
+ homepage_uri: https://github.com/2moe/cinnabar
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.1.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.7.2
61
+ specification_version: 4
62
+ summary: CI Utils
63
+ test_files: []