Replace usage of DelegateClass with SimpleDelegator.

This commit is contained in:
Markus Reiter 2020-09-20 05:50:33 +02:00
parent f27d7a21d7
commit 17544fc275
5 changed files with 21 additions and 14 deletions

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "delegate"
require "extend/hash_validator" require "extend/hash_validator"
using HashValidator using HashValidator
@ -8,7 +10,7 @@ module Cask
# Class corresponding to the `conflicts_with` stanza. # Class corresponding to the `conflicts_with` stanza.
# #
# @api private # @api private
class ConflictsWith < DelegateClass(Hash) class ConflictsWith < SimpleDelegator
VALID_KEYS = [ VALID_KEYS = [
:formula, :formula,
:cask, :cask,
@ -18,12 +20,13 @@ module Cask
:java, :java,
].freeze ].freeze
def initialize(**pairs) def initialize(**options)
pairs.assert_valid_keys!(*VALID_KEYS) options.assert_valid_keys!(*VALID_KEYS)
super(pairs.transform_values { |v| Set.new(Array(v)) }) conflicts = options.transform_values { |v| Set.new(Array(v)) }
conflicts.default = Set.new
self.default = Set.new super(conflicts)
end end
def to_json(generator) def to_json(generator)

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "delegate"
require "requirements/macos_requirement" require "requirements/macos_requirement"
module Cask module Cask
@ -7,7 +9,7 @@ module Cask
# Class corresponding to the `depends_on` stanza. # Class corresponding to the `depends_on` stanza.
# #
# @api private # @api private
class DependsOn < DelegateClass(Hash) class DependsOn < SimpleDelegator
VALID_KEYS = Set.new([ VALID_KEYS = Set.new([
:formula, :formula,
:cask, :cask,

View File

@ -6,7 +6,7 @@ require "cask_dependent"
# A collection of dependencies. # A collection of dependencies.
# #
# @api private # @api private
class Dependencies < DelegateClass(Array) class Dependencies < SimpleDelegator
def initialize(*args) def initialize(*args)
super(args) super(args)
end end
@ -41,7 +41,7 @@ end
# A collection of requirements. # A collection of requirements.
# #
# @api private # @api private
class Requirements < DelegateClass(Set) class Requirements < SimpleDelegator
def initialize(*args) def initialize(*args)
super(Set.new(args)) super(Set.new(args))
end end

View File

@ -1,9 +1,11 @@
# typed: strict # typed: strict
class User < String class User < SimpleDelegator
def gui? include Kernel
end
def self.current sig { returns(T::Boolean) }
end def gui?; end
sig { returns(T.nilable(T.attached_class)) }
def self.current; end
end end

View File

@ -8,7 +8,7 @@ require "system_command"
# A system user. # A system user.
# #
# @api private # @api private
class User < DelegateClass(String) class User < SimpleDelegator
# Return whether the user has an active GUI session. # Return whether the user has an active GUI session.
def gui? def gui?
out, _, status = system_command "who" out, _, status = system_command "who"