rbs_mini_magick 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d110222be265ce0165e6eb2ed2b0632ceb5ad05b52a99d42b6a00e61cc54a12
4
+ data.tar.gz: d42c86a6def43b291ba45467fbccb48d0ffd455e49b5f211e77f886bbb98b29b
5
+ SHA512:
6
+ metadata.gz: 7bed2461449acac38299d412512a10ab9b175bec7cb9c52e77606fead4cb2e06b585691e6be5b82c28eaf24eb918f0471aa266416a99a744d861275a3cab8420
7
+ data.tar.gz: 99c345541e98bebd636b3c7fa3a23d273626b937c5830bd8611dea2840e2574a51ea08cd2ec1b27077e16d9bfd006ec0aba8accc5a7bab0b916e8c37f95242e3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## [0.1.0] - 2024-07-28
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # RbsMiniMagick
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ ```
8
+ $ bundle add rbs_mini_magick
9
+ ```
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ ```
14
+ $ gem install rbs_mini_magick
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```sh
20
+ $ bundle exec rbs-mini-magick generate
21
+ ```
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aki19035vc/rbs_mini_magick.
32
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/aki19035vc/rbs_mini_magick/blob/main/CODE_OF_CONDUCT.md).
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
+
38
+ ## Code of Conduct
39
+
40
+ Everyone interacting in the RbsMiniMagick project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aki19035vc/rbs_mini_magick/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rbs_mini_magick"
5
+
6
+ RbsMiniMagick::CLI.new(ARGV, io: $stdout).run
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::Builder
6
+ class Builder
7
+ # @param mini_magick_version [Gem::Version]
8
+ # @return [void]
9
+ def initialize(mini_magick_version:)
10
+ @mini_magick_version = mini_magick_version
11
+ end
12
+
13
+ # @return [String]
14
+ def run
15
+ rbs = case mini_magick_version
16
+ when Range.new(Gem::Version.new("5.0"), nil)
17
+ v5_0
18
+ else
19
+ raise Error, "#{mini_magick_version} does not support"
20
+ end
21
+
22
+ format_rbs(rbs)
23
+ end
24
+
25
+ private
26
+
27
+ # @!attribute [r] mini_magick_version
28
+ # @return [Gem::Version]
29
+ attr_reader :mini_magick_version
30
+
31
+ # @return [Hash<String, Array<RbsMiniMagick::ImageMagick::CommandLineOption>>]
32
+ def options_by_tool
33
+ @options_by_tool ||= ImageMagick::TOOL_NAMES.to_h do |tool|
34
+ tool.then { ImageMagick::UsageFetcher.new(tool_name: _1).run }
35
+ .then { ImageMagick::UsageParser.new(raw_usage: _1).run }
36
+ .then { [tool, _1] }
37
+ end
38
+ end
39
+
40
+ # @return [Array<RbsMiniMagick::ImageMagick::CommandLineOption>]
41
+ def mogrify_options
42
+ @mogrify_options ||= options_by_tool.fetch("mogrify")
43
+ end
44
+
45
+ # @param rbs [String]
46
+ # @return [String]
47
+ def format_rbs(rbs)
48
+ out = StringIO.new
49
+ decls = RBS::Parser.parse_signature(rbs).then { _1[1] + _1[2] }
50
+
51
+ RBS::Writer.new(out: out).write(decls)
52
+
53
+ out.string
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::ImageClass
6
+ class ImageClass
7
+ # @param mogrify_options [Array<RbsMiniMagick::ImageMagick::CommandLineOption>]
8
+ # @return [void]
9
+ def initialize(mogrify_options:)
10
+ @mogrify_options = mogrify_options
11
+ end
12
+
13
+ private
14
+
15
+ # @!attribute [r] mogrify_options
16
+ # @return [Array<RbsMiniMagick::ImageMagick::CommandLineOption>]
17
+ attr_reader :mogrify_options
18
+
19
+ # @return [Array<String>]
20
+ def delegated_mogrify_methods
21
+ image_instance_methods = MiniMagick::Image.instance_methods.to_set(&:to_s)
22
+
23
+ mogrify_options.filter_map do |item|
24
+ next if image_instance_methods.include?(item.normalized_name)
25
+
26
+ item.to_method_signature("self")
27
+ end.uniq
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::SingletonMethod
6
+ class SingletonMethod
7
+ # @param tool_name [String]
8
+ # @return [void]
9
+ def initialize(tool_name:)
10
+ @tool_name = tool_name
11
+ end
12
+
13
+ private
14
+
15
+ # @!attribute [r] tool_name
16
+ # @return [String]
17
+ attr_reader :tool_name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::ToolInterface
6
+ class ToolInterface
7
+ # @param tool_name [String]
8
+ # @param options [Array<RbsMiniMagick::ImageMagick::CommandLineOption>]
9
+ # @return [void]
10
+ def initialize(tool_name:, options:)
11
+ @tool_name = tool_name
12
+ @options = options
13
+ end
14
+
15
+ private
16
+
17
+ # @!attribute [r] tool_name
18
+ # @return [String]
19
+ attr_reader :tool_name
20
+ # @!attribute [r] options
21
+ # @return [Array<RbsMiniMagick::ImageMagick::CommandLineOption>]
22
+ attr_reader :options
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::ToolSubclass
6
+ class ToolSubclass
7
+ # @param tool_name [String]
8
+ # @return [void]
9
+ def initialize(tool_name:)
10
+ @tool_name = tool_name
11
+ end
12
+
13
+ private
14
+
15
+ # @!attribute [r] tool_name
16
+ # @return [String]
17
+ attr_reader :tool_name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builder
6
+ class Builder
7
+ # @return [String]
8
+ def v5_0 # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
9
+ tool_interface_methods = options_by_tool.map do |tool, options|
10
+ Builders::ToolInterface.new(tool_name: tool, options: options).v5_0
11
+ end.join("\n")
12
+
13
+ tool_subclasses = options_by_tool.map do |tool, _|
14
+ Builders::ToolSubclass.new(tool_name: tool).v5_0
15
+ end.join("\n")
16
+
17
+ singleton_methods = options_by_tool.map do |tool, _|
18
+ Builders::SingletonMethod.new(tool_name: tool).v5_0
19
+ end.join("\n")
20
+
21
+ image_class = Builders::ImageClass.new(mogrify_options: mogrify_options).v5_0
22
+
23
+ <<~RBS
24
+ module MiniMagick
25
+ #{tool_interface_methods}
26
+
27
+ #{tool_subclasses}
28
+
29
+ #{singleton_methods}
30
+
31
+ #{image_class}
32
+ end
33
+ RBS
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::ImageClass
6
+ class ImageClass
7
+ # @return [String]
8
+ def v5_0
9
+ <<~RBS
10
+ class Image
11
+ def initialize: (_ToS input_path, ?Tempfile? tempfile) ?{ (Tool & _Mogrify[Tool]) -> void } -> void
12
+ | ...
13
+
14
+ def combine_options: () { (Tool & _Mogrify[Tool]) -> void } -> self
15
+ | ...
16
+
17
+ def composite: (instance other_image, ?String output_extension, ?untyped? mask) ?{ (Tool & _Composite[Tool]) -> void } -> instance
18
+ | ...
19
+
20
+ def identify: () ?{ (Tool & _Identify[Tool]) -> void } -> String
21
+ | ...
22
+
23
+ def mogrify: (?Integer? page) ?{ (Tool & _Mogrify[Tool]) -> void } -> self
24
+ | ...
25
+
26
+ #{delegated_mogrify_methods.join("\n")}
27
+ end
28
+ RBS
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::SingletonMethod
6
+ class SingletonMethod
7
+ # @return [String]
8
+ def v5_0
9
+ interface_name = "_#{tool_name.capitalize}"
10
+ args = "?errors: bool, ?warnings: bool, ?stdin: _ToS, ?timeout: Integer?, **untyped options"
11
+
12
+ <<~RBS
13
+ def self.#{tool_name}: (#{args}) -> (Tool & #{interface_name}[Tool])
14
+ | (#{args}) { (Tool & #{interface_name}[Tool]) -> void } -> String
15
+ | ...
16
+ RBS
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::ToolInterface
6
+ class ToolInterface
7
+ # @return [String]
8
+ def v5_0
9
+ tool_methods = options.map { _1.to_method_signature("[T]") }
10
+ .uniq.join("\n")
11
+
12
+ <<~RBS
13
+ interface _#{tool_name.capitalize}[T]
14
+ #{tool_methods}
15
+ end
16
+ RBS
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module Builders
5
+ # RbsMiniMagick::Builders::ToolSubclass
6
+ class ToolSubclass
7
+ # @return [String]
8
+ def v5_0
9
+ <<~RBS
10
+ class Tool
11
+ class #{tool_name.capitalize} < Tool
12
+ include _#{tool_name.capitalize}
13
+ end
14
+ end
15
+ RBS
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ # RbsMiniMagick::Builders
5
+ module Builders; end
6
+ end
7
+
8
+ require_relative "builders/builder"
9
+ require_relative "builders/tool_interface"
10
+ require_relative "builders/tool_subclass"
11
+ require_relative "builders/singleton_method"
12
+ require_relative "builders/image_class"
13
+
14
+ require_relative "builders/v5_0/builder"
15
+ require_relative "builders/v5_0/tool_interface"
16
+ require_relative "builders/v5_0/tool_subclass"
17
+ require_relative "builders/v5_0/singleton_method"
18
+ require_relative "builders/v5_0/image_class"
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ # RbsMiniMagick::CLI
5
+ class CLI
6
+ # @param args [Array<String>]
7
+ # @param io [::IO]
8
+ # @return [void]
9
+ def initialize(args, io:)
10
+ @args = args
11
+ @options = {}
12
+ @io = io
13
+ end
14
+
15
+ # @return [Integer]
16
+ def run # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
17
+ parse!
18
+
19
+ return 0 if help? || version?
20
+
21
+ case options[:command]
22
+ when "generate"
23
+ Generator.new(
24
+ mini_magick_version: options[:mini_magick_version],
25
+ output_dir: options[:output_dir]
26
+ ).run
27
+ else
28
+ raise ArgumentError, "Invalid command: #{options[:command]}"
29
+ end
30
+
31
+ 0
32
+ rescue Error => e
33
+ io.puts e.message
34
+ 1
35
+ rescue OptionParser::InvalidOption, ArgumentError => e
36
+ io.puts e.message
37
+ io.puts help
38
+ 1
39
+ rescue Interrupt
40
+ io.puts "Bye!"
41
+ 1
42
+ end
43
+
44
+ # @return [String]
45
+ def help
46
+ parser.help
47
+ end
48
+
49
+ private
50
+
51
+ # @!attribute [r] args
52
+ # @return [Array<String>]
53
+ attr_reader :args
54
+ # @!attribute [r] options
55
+ # @return [Hash]
56
+ attr_reader :options
57
+ # @!attribute [r] io
58
+ # @return [::IO]
59
+ attr_reader :io
60
+
61
+ # @return [void]
62
+ # @raise [OptionParser::InvalidOption]
63
+ def parse!
64
+ command = parser.parse(args).first || ""
65
+ @options.merge!(command: command)
66
+ end
67
+
68
+ # @return [OptionParser]
69
+ def parser # rubocop:disable Metrics/MethodLength
70
+ OptionParser.new do |opts|
71
+ opts.banner = "Usage: rbs_mini_magick [command] [options]"
72
+ opts.separator <<~COMMANDS
73
+ Commands:
74
+ generate Generate mini_magick signature
75
+ COMMANDS
76
+ opts.separator("Options:")
77
+ opts.on("--mini-magick-version VALUE", String) { @options[:mini_magick_version] = _1 }
78
+ opts.on("--output-dir VALUE", String) { @options[:output_dir] = _1 }
79
+ opts.on_tail("-h", "--help", "Show help") { @options[:help] = true }
80
+ opts.on_tail("--version", "Show version") { @options[:version] = true }
81
+ end
82
+ end
83
+
84
+ # @return [Boolean]
85
+ def help?
86
+ return false unless options.include?(:help)
87
+
88
+ io.puts help
89
+ true
90
+ end
91
+
92
+ # @return [Boolean]
93
+ def version?
94
+ return false unless options.include?(:version)
95
+
96
+ io.puts "RbsMiniMagick: #{RbsMiniMagick::VERSION}"
97
+ true
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ # RbsMiniMagick::Generator
5
+ class Generator
6
+ # @param mini_magick_version [Gem::Version, nil]
7
+ # @param output_dir [String, nil]
8
+ # @return [void]
9
+ def initialize(mini_magick_version:, output_dir:)
10
+ @mini_magick_version = mini_magick_version || MiniMagick.version
11
+ @output_dir = output_dir&.then { Pathname(_1) } ||
12
+ Bundler.root.join("sig", "rbs_mini_magick") # steep:ignore
13
+ @output_path = @output_dir.join("mini_magick.rbs")
14
+ end
15
+
16
+ # @return [void]
17
+ def run
18
+ rbs = Builders::Builder.new(mini_magick_version: mini_magick_version).run
19
+ FileUtils.mkdir_p(output_dir.to_s)
20
+ File.write(output_path.to_s, rbs)
21
+ end
22
+
23
+ private
24
+
25
+ # @!attribute [r] mini_magick_version
26
+ # @return [Gem::Version]
27
+ attr_reader :mini_magick_version
28
+ # @!attribute [r] output_dir
29
+ # @return [Pathname]
30
+ attr_reader :output_dir
31
+ # @!attribute [r] output_path
32
+ # @return [Pathname]
33
+ attr_reader :output_path
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module ImageMagick
5
+ # RbsMiniMagick::ImageMagick::CommandLineOption
6
+ class CommandLineOption
7
+ # @!attribute [r] normalized_name
8
+ # @return [String]
9
+ attr_reader :normalized_name
10
+
11
+ # @param name [String]
12
+ # @param args [Array<String>]
13
+ # @return [void]
14
+ def initialize(name:, args:)
15
+ @name = name
16
+ @args = args
17
+ @normalized_name = name.delete_prefix("-").gsub(/\W/, "_")
18
+ end
19
+
20
+ # @param return_type [String]
21
+ # @return [String]
22
+ def to_method_signature(return_type)
23
+ sig_args = args.empty? ? "" : "*_ToS args"
24
+
25
+ "def #{normalized_name}: (#{sig_args}) -> #{return_type}"
26
+ end
27
+
28
+ private
29
+
30
+ # @!attribute [r] name
31
+ # @return [String]
32
+ attr_reader :name
33
+ # @!attribute [r] args
34
+ # @return [Array<String>]
35
+ attr_reader :args
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module ImageMagick
5
+ # RbsMiniMagick::ImageMagick::UsageFetcher
6
+ class UsageFetcher
7
+ # @param tool_name [String]
8
+ # @return [void]
9
+ def initialize(tool_name:)
10
+ @tool_name = tool_name
11
+ end
12
+
13
+ # @return [String]
14
+ def run
15
+ tool = MiniMagick::Tool.new(tool_name)
16
+ tool.help # steep:ignore
17
+ tool.call(errors: false, warnings: false)
18
+ end
19
+
20
+ private
21
+
22
+ # @!attribute [r] tool_name
23
+ # @return [String]
24
+ attr_reader :tool_name
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ module ImageMagick
5
+ # RbsMiniMagick::ImageMagick::UsageParser
6
+ class UsageParser
7
+ # @param raw_usage [String]
8
+ # @return [void]
9
+ def initialize(raw_usage:)
10
+ @raw_usage = raw_usage
11
+ end
12
+
13
+ # @return [Array<RbsMiniMagick::ImageMagick::CommandLineOption>]
14
+ def run
15
+ parse_raw_command_line_options
16
+ .map { build_command_line_option(_1) }
17
+ end
18
+
19
+ private
20
+
21
+ # @!attribute [r] raw_usage
22
+ # @return [String]
23
+ attr_reader :raw_usage
24
+
25
+ # @return [Array<String>]
26
+ def parse_raw_command_line_options
27
+ raw_usage.split("\n").filter_map do |line|
28
+ line.match(/^\s*(-\S+(?: \S+)*)\s*/)&.then { _1[1] }
29
+ end
30
+ end
31
+
32
+ # @param raw_string [String]
33
+ # @return [RbsMiniMagick::ImageMagick::CommandLineOption]
34
+ def build_command_line_option(raw_string)
35
+ splited = raw_string.split
36
+
37
+ CommandLineOption.new(
38
+ name: String(splited.first),
39
+ args: splited[1..] || []
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ # RbsMiniMagick::ImageMagick
5
+ module ImageMagick
6
+ # @return [String<String>]
7
+ TOOL_NAMES = %w[
8
+ animate
9
+ compare
10
+ composite
11
+ conjure
12
+ convert
13
+ display
14
+ identify
15
+ import
16
+ mogrify
17
+ montage
18
+ stream
19
+ ].freeze
20
+ public_constant :TOOL_NAMES
21
+ end
22
+ end
23
+
24
+ require_relative "image_magick/command_line_option"
25
+ require_relative "image_magick/usage_fetcher"
26
+ require_relative "image_magick/usage_parser"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RbsMiniMagick
4
+ # RbsMiniMagick::VERSION
5
+ VERSION = "0.1.0"
6
+ public_constant :VERSION
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+ require "open3"
5
+ require "optparse"
6
+ require "pathname"
7
+ require "rbs"
8
+ require "stringio"
9
+
10
+ require "mini_magick"
11
+
12
+ # RbsMiniMagick
13
+ module RbsMiniMagick
14
+ # RbsMiniMagick::Error
15
+ class Error < StandardError; end
16
+ end
17
+
18
+ require_relative "rbs_mini_magick/version"
19
+ require_relative "rbs_mini_magick/image_magick"
20
+ require_relative "rbs_mini_magick/builders"
21
+ require_relative "rbs_mini_magick/generator"
22
+ require_relative "rbs_mini_magick/cli"
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbs_mini_magick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aki19035vc
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rbs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3'
41
+ description: Generate mini_magick signature
42
+ email:
43
+ - 52433677+aki19035vc@users.noreply.github.com
44
+ executables:
45
+ - rbs-mini-magick
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - README.md
52
+ - exe/rbs-mini-magick
53
+ - lib/rbs_mini_magick.rb
54
+ - lib/rbs_mini_magick/builders.rb
55
+ - lib/rbs_mini_magick/builders/builder.rb
56
+ - lib/rbs_mini_magick/builders/image_class.rb
57
+ - lib/rbs_mini_magick/builders/singleton_method.rb
58
+ - lib/rbs_mini_magick/builders/tool_interface.rb
59
+ - lib/rbs_mini_magick/builders/tool_subclass.rb
60
+ - lib/rbs_mini_magick/builders/v5_0/builder.rb
61
+ - lib/rbs_mini_magick/builders/v5_0/image_class.rb
62
+ - lib/rbs_mini_magick/builders/v5_0/singleton_method.rb
63
+ - lib/rbs_mini_magick/builders/v5_0/tool_interface.rb
64
+ - lib/rbs_mini_magick/builders/v5_0/tool_subclass.rb
65
+ - lib/rbs_mini_magick/cli.rb
66
+ - lib/rbs_mini_magick/generator.rb
67
+ - lib/rbs_mini_magick/image_magick.rb
68
+ - lib/rbs_mini_magick/image_magick/command_line_option.rb
69
+ - lib/rbs_mini_magick/image_magick/usage_fetcher.rb
70
+ - lib/rbs_mini_magick/image_magick/usage_parser.rb
71
+ - lib/rbs_mini_magick/version.rb
72
+ homepage: https://github.com/aki19035vc/rbs_mini_magick
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ homepage_uri: https://github.com/aki19035vc/rbs_mini_magick
77
+ source_code_uri: https://github.com/aki19035vc/rbs_mini_magick
78
+ changelog_uri: https://github.com/aki19035vc/rbs_mini_magick/blob/master/CHANGELOG.md
79
+ rubygems_mfa_required: 'true'
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.0.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.5.16
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Generate mini_magick signature
99
+ test_files: []