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(cookies: nil, header: nil, homebrew_curl: nil, post_form: nil, post_json: nil, referer: nil, user_agent: nil) ⇒ void

Parameters:

  • 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 (Boolean, 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 :cookies, T.nilable(T::Hash[String, String])
prop :header, T.nilable(T.any(String, T::Array[String]))
prop :homebrew_curl, T.nilable(T::Boolean)
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

#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_curlBoolean?

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:

  • (Boolean, nil)


# File ''

prop :homebrew_curl, T.nilable(T::Boolean)

#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)


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

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 are removed from other before merging if it is an Options object, as these are unitiailized values. This ensures that existing values in self aren't unexpectedly overwritten with defaults.

Parameters:

Returns:



65
66
67
68
69
70
71
72
73
74
# File 'livecheck/options.rb', line 65

def merge(other)
  return dup if other.empty?

  this_hash = to_h
  other_hash = other.is_a?(Options) ? other.to_h : other
  return dup if this_hash == other_hash

  new_options = this_hash.merge(other_hash)
  Options.new(**new_options)
end

#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 are removed from other before merging if it is an Options object, as these are unitiailized values. This ensures that existing values in self aren't unexpectedly overwritten with defaults.

Parameters:

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'livecheck/options.rb', line 82

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

  if other.is_a?(Options)
    return self if self == other

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

      instance_variable_set(ivar, v)
    end
  else
    other.each do |k, v|
      cmd = :"#{k}="
      send(cmd, v) if respond_to?(cmd)
    end
  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)


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

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:



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

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:



50
51
52
# File 'livecheck/options.rb', line 50

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:



36
37
38
39
40
41
42
43
44
45
46
# File 'livecheck/options.rb', line 36

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