From 5540eac62508ac7d221d80ea51edea50975aee0c Mon Sep 17 00:00:00 2001 From: Markus Reiter <me@reitermark.us> Date: Mon, 17 Aug 2020 19:53:37 +0200 Subject: [PATCH] Refactor and document `Options`. --- Library/Homebrew/cmd/info.rb | 2 +- Library/Homebrew/cmd/options.rb | 2 +- Library/Homebrew/options.rb | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 42089d4d87..f54f833ebb 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -239,7 +239,7 @@ module Homebrew if !f.options.empty? || f.head || f.devel ohai "Options" - Homebrew.dump_options_for_formula f + Options.dump_for_formula f end caveats = Caveats.new(f) diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index f82a029bcf..cf6c7aaad8 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -80,7 +80,7 @@ module Homebrew puts f.options.as_flags.sort * " " else puts f.full_name if formulae.length > 1 - dump_options_for_formula f + Options.dump_for_formula f puts end end diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb index c386c2ee4b..7823e1ebbf 100644 --- a/Library/Homebrew/options.rb +++ b/Library/Homebrew/options.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# A formula option. +# +# @api private class Option attr_reader :name, :description, :flag @@ -33,6 +36,9 @@ class Option end end +# A deprecated formula option. +# +# @api private class DeprecatedOption attr_reader :old, :current @@ -55,6 +61,9 @@ class DeprecatedOption alias eql? == end +# A collection of formula options. +# +# @api private class Options include Enumerable @@ -112,12 +121,8 @@ class Options def inspect "#<#{self.class.name}: #{to_a.inspect}>" end -end - -module Homebrew - module_function - def dump_options_for_formula(f) + def self.dump_for_formula(f) f.options.sort_by(&:flag).each do |opt| puts "#{opt.flag}\n\t#{opt.description}" end -- GitLab