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

Parameters:

  • 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 => String}, nil) (defaults to: nil)

    JSON data to use when making a POST request.



# File ''

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

Instance Attribute Details

#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 => 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.

JSON data to use when making a POST request.

Returns:



# File ''

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

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)


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

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:



48
49
50
51
52
53
54
55
56
57
# File 'livecheck/options.rb', line 48

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:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'livecheck/options.rb', line 65

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)


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

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:



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

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:



33
34
35
# File 'livecheck/options.rb', line 33

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:



23
24
25
26
27
28
29
# File 'livecheck/options.rb', line 23

def url_options
  {
    homebrew_curl:,
    post_form:,
    post_json:,
  }
end