Class: Dependabot::Credential

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, T::Sig
Defined in:
lib/dependabot/credential.rb

Constant Summary collapse

Value =
T.type_alias { T.nilable(String) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credential) ⇒ Credential

Returns a new instance of Credential.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dependabot/credential.rb', line 17

def initialize(credential)
  @replaces_base = T.let(credential["replaces-base"] == true, T::Boolean)
  credential.delete("replaces-base")

  raw_scope = credential.delete("scope")
  @scope = T.let(
    case raw_scope
    when String then [raw_scope]
    when Array then raw_scope
    end,
    T.nilable(T::Array[String])
  )

  @credential = T.let(
    credential.to_h do |key, value|
      raise TypeError, "credential #{key} must be a string or nil" unless value.nil? || value.is_a?(String)

      [key, value]
    end,
    T::Hash[String, Value]
  )
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



46
47
48
# File 'lib/dependabot/credential.rb', line 46

def scope
  @scope
end

Instance Method Details

#[](key) ⇒ Object



49
50
51
# File 'lib/dependabot/credential.rb', line 49

def [](key)
  @credential[key]
end

#merge(other) ⇒ Object



54
55
56
# File 'lib/dependabot/credential.rb', line 54

def merge(other)
  Credential.new(@credential.merge(other.to_h))
end

#replaces_base?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/dependabot/credential.rb', line 41

def replaces_base?
  @replaces_base
end

#to_hObject



59
60
61
# File 'lib/dependabot/credential.rb', line 59

def to_h
  @credential
end