Remove OpenStruct use in Tab
This commit is contained in:
parent
0d5e291fe1
commit
3018793f93
@ -390,7 +390,6 @@ Style/NumericLiterals:
|
|||||||
Style/OpenStructUse:
|
Style/OpenStructUse:
|
||||||
Exclude:
|
Exclude:
|
||||||
- "Homebrew/cli/args.rb"
|
- "Homebrew/cli/args.rb"
|
||||||
- "Homebrew/tab.rb"
|
|
||||||
- "Taps/**/*.rb"
|
- "Taps/**/*.rb"
|
||||||
|
|
||||||
# Rescuing `StandardError` is an understood default.
|
# Rescuing `StandardError` is an understood default.
|
||||||
|
|||||||
@ -1,23 +1,22 @@
|
|||||||
# typed: false
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cxxstdlib"
|
require "cxxstdlib"
|
||||||
require "ostruct"
|
|
||||||
require "options"
|
require "options"
|
||||||
require "json"
|
require "json"
|
||||||
require "development_tools"
|
require "development_tools"
|
||||||
require "extend/cachable"
|
require "extend/cachable"
|
||||||
|
|
||||||
# Inherit from OpenStruct to gain a generic initialization method that takes a
|
# Rather than calling `new` directly, use one of the class methods like {Tab.create}.
|
||||||
# hash and creates an attribute for each key and value. Rather than calling
|
class Tab
|
||||||
# `new` directly, use one of the class methods like {Tab.create}.
|
|
||||||
class Tab < OpenStruct
|
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
|
|
||||||
extend Cachable
|
extend Cachable
|
||||||
|
|
||||||
FILENAME = "INSTALL_RECEIPT.json"
|
FILENAME = "INSTALL_RECEIPT.json"
|
||||||
|
|
||||||
|
attr_accessor :homebrew_version, :used_options, :unused_options, :tabfile, :built_as_bottle, :installed_as_dependency, :installed_on_request, :changed_files, :poured_from_bottle, :loaded_from_api, :time, :source_modified_time, :stdlib, :compiler, :aliases, :runtime_dependencies, :arch, :source, :built_on, :HEAD
|
||||||
|
|
||||||
# Instantiates a Tab for a new installation of a formula.
|
# Instantiates a Tab for a new installation of a formula.
|
||||||
def self.create(formula, compiler, stdlib)
|
def self.create(formula, compiler, stdlib)
|
||||||
build = formula.build
|
build = formula.build
|
||||||
@ -120,7 +119,7 @@ class Tab < OpenStruct
|
|||||||
empty
|
empty
|
||||||
end
|
end
|
||||||
|
|
||||||
tab["tabfile"] = path
|
tab.tabfile = path
|
||||||
tab
|
tab
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -226,6 +225,10 @@ class Tab < OpenStruct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize(attributes = {})
|
||||||
|
attributes.each { |key, value| instance_variable_set("@#{key}", value) }
|
||||||
|
end
|
||||||
|
|
||||||
def any_args_or_options?
|
def any_args_or_options?
|
||||||
!used_options.empty? || !unused_options.empty?
|
!used_options.empty? || !unused_options.empty?
|
||||||
end
|
end
|
||||||
@ -255,15 +258,15 @@ class Tab < OpenStruct
|
|||||||
end
|
end
|
||||||
|
|
||||||
def used_options
|
def used_options
|
||||||
Options.create(super)
|
Options.create(@used_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unused_options
|
def unused_options
|
||||||
Options.create(super)
|
Options.create(@unused_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compiler
|
def compiler
|
||||||
super || DevelopmentTools.default_compiler
|
@compiler || DevelopmentTools.default_compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
def parsed_homebrew_version
|
def parsed_homebrew_version
|
||||||
@ -275,7 +278,7 @@ class Tab < OpenStruct
|
|||||||
def runtime_dependencies
|
def runtime_dependencies
|
||||||
# Homebrew versions prior to 1.1.6 generated incorrect runtime dependency
|
# Homebrew versions prior to 1.1.6 generated incorrect runtime dependency
|
||||||
# lists.
|
# lists.
|
||||||
super unless parsed_homebrew_version < "1.1.6"
|
@runtime_dependencies unless parsed_homebrew_version < "1.1.6"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cxxstdlib
|
def cxxstdlib
|
||||||
@ -324,7 +327,7 @@ class Tab < OpenStruct
|
|||||||
|
|
||||||
sig { returns(Time) }
|
sig { returns(Time) }
|
||||||
def source_modified_time
|
def source_modified_time
|
||||||
Time.at(super || 0)
|
Time.at(@source_modified_time || 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(options = nil)
|
def to_json(options = nil)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user