Class: Homebrew::Livecheck::Options Private

Inherits:
T::Struct
  • Object
show all
Defined in:
livecheck/options.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Options to modify livecheck's behavior. These primarily come from livecheck blocks but they can also be set by livecheck at runtime.

Option values use a nil default to indicate that the value has not been set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compressed: nil, cookies: nil, header: nil, homebrew_curl: nil, post_form: nil, post_json: nil, referer: nil, user_agent: nil) ⇒ void

Parameters:

  • compressed (false, nil) (defaults to: nil)

    Whether to request a compressed response.

  • cookies (Hash{String => String}, nil) (defaults to: nil)

    Cookies for curl to use when making a request.

  • header (String, Array<String>, nil) (defaults to: nil)

    Header(s) for curl to use when making a request.

  • homebrew_curl (true, nil) (defaults to: nil)

    Whether to use brewed curl.

  • post_form (Hash{Symbol => String}, nil) (defaults to: nil)

    Form data to use when making a POST request.

  • post_json (Hash{Symbol => T.anything}, nil) (defaults to: nil)

    JSON data to use when making a POST request.

  • referer (String, nil) (defaults to: nil)

    Referer for curl to use when making a request.

  • user_agent (String, Symbol, nil) (defaults to: nil)

    User agent for curl to use when making a request. Symbol arguments should use a value supported by Utils::Curl.curl_args.



# File ''

prop :compressed, T.nilable(FalseClass)
prop :cookies, T.nilable(T::Hash[String, String])
prop :header, T.nilable(T.any(String, T::Array[String]))
prop :homebrew_curl, T.nilable(TrueClass)
prop :post_form, T.nilable(T::Hash[Symbol, String])
prop :post_json, T.nilable(T::Hash[Symbol, T.anything])
prop :referer, T.nilable(String)
prop :user_agent, T.nilable(T.any(String, Symbol))

Instance Attribute Details

#compressedfalse?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Whether to request a compressed response.

Returns:

  • (false, nil)


# File ''

prop :compressed, T.nilable(FalseClass)

#cookiesHash{String => String}?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Cookies for curl to use when making a request.

Returns:



# File ''

prop :cookies, T.nilable(T::Hash[String, String])

#headerString, ...

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Header(s) for curl to use when making a request.

Returns:



# File ''

prop :header, T.nilable(T.any(String, T::Array[String]))

#homebrew_curltrue?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Whether to use brewed curl.

Returns:

  • (true, nil)


# File ''

prop :homebrew_curl, T.nilable(TrueClass)

#post_formHash{Symbol => String}?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Form data to use when making a POST request.

Returns:



# File ''

prop :post_form, T.nilable(T::Hash[Symbol, String])

#post_jsonHash{Symbol => T.anything}?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

JSON data to use when making a POST request.

Returns:



# File ''

prop :post_json, T.nilable(T::Hash[Symbol, T.anything])

#refererString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Referer for curl to use when making a request.

Returns:



# File ''

prop :referer, T.nilable(String)

#user_agentString, ...

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

User agent for curl to use when making a request. Symbol arguments should use a value supported by Utils::Curl.curl_args.

Returns:



# File ''

prop :user_agent, T.nilable(T.any(String, Symbol))

Instance Method Details

#empty?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Whether the object has only default values.

Returns:

  • (Boolean)


123
# File 'livecheck/options.rb', line 123

def empty? = to_hash.empty?

#merge(other) ⇒ Options

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a new object formed by merging other values with a copy of self.

nil values from other are skipped, as these are uninitialized. This ensures that existing values in self aren't unexpectedly overwritten by defaults.

Parameters:

Returns:



69
# File 'livecheck/options.rb', line 69

def merge(other) = deep_dup.merge!(other)

#merge!(other) ⇒ Options

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Merges values from other into self and returns self.

nil values from other are skipped, as these are uninitialized. This ensures that existing values in self aren't unexpectedly overwritten by defaults.

Parameters:

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'livecheck/options.rb', line 77

def merge!(other)
  return self if other.empty?

  # These options are mutually exclusive, so we can't know which should be
  # used when `other` has both
  other_post_form = other.post_form
  other_post_json = other.post_json
  if other_post_form && other_post_json
    raise ArgumentError, "Cannot merge provided options using both `post_form` and `post_json`"
  end

  return self if self == other

  other.instance_variables.each do |ivar|
    next if (val = T.let(other.instance_variable_get(ivar), Object)).nil?

    public_send(:"#{ivar.to_s.delete_prefix("@")}=", val.deep_dup)
  end

  # Merging one of these options should unset the opposite value in `self`
  if !other_post_form.nil?
    self.post_json = nil
  elsif !other_post_json.nil?
    self.post_form = nil
  end

  self
end

#present?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Whether the object has any non-default values.

Returns:

  • (Boolean)


127
# File 'livecheck/options.rb', line 127

def present? = !empty?

#to_hHash{Symbol => T.untyped}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a Hash of all instance variables, using Symbol keys.

Returns:



60
# File 'livecheck/options.rb', line 60

def to_h = to_hash.transform_keys(&:to_sym)

#to_hashHash{String => T.untyped}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a Hash of all instance variables, using String keys.

Returns:



54
55
56
# File 'livecheck/options.rb', line 54

def to_hash
  T.let(serialize, T::Hash[String, T.untyped])
end

#url_optionsHash{Symbol => T.untyped}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns a Hash of options that are provided as arguments to url.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'livecheck/options.rb', line 39

def url_options
  {
    compressed:,
    cookies:,
    header:,
    homebrew_curl:,
    post_form:,
    post_json:,
    referer:,
    user_agent:,
  }
end