Class: Dependabot::RustToolchain::Channel

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
lib/dependabot/rust_toolchain/channel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stability: nil, date: nil, version: nil) ⇒ Channel

Returns a new instance of Channel.



25
26
27
28
29
# File 'lib/dependabot/rust_toolchain/channel.rb', line 25

def initialize(stability: nil, date: nil, version: nil)
  @stability = stability
  @date = date
  @version = version
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



19
20
21
# File 'lib/dependabot/rust_toolchain/channel.rb', line 19

def date
  @date
end

#stabilityObject (readonly)

Returns the value of attribute stability.



16
17
18
# File 'lib/dependabot/rust_toolchain/channel.rb', line 16

def stability
  @stability
end

#versionObject

Returns the value of attribute version.



22
23
24
# File 'lib/dependabot/rust_toolchain/channel.rb', line 22

def version
  @version
end

Class Method Details

.from_parsed_data(parsed_data) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/dependabot/rust_toolchain/channel.rb', line 33

def self.from_parsed_data(parsed_data)
  new(
    stability: parsed_data[:stability],
    date: parsed_data[:date],
    version: parsed_data[:version]
  )
end

Instance Method Details

#<=>(other) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dependabot/rust_toolchain/channel.rb', line 54

def <=>(other)
  return nil unless other.is_a?(Channel)
  return nil unless channel_type == other.channel_type

  case channel_type
  in ChannelType::Version
    compare_versions(T.must(version), T.must(other.version))
  in ChannelType::DatedStability
    # Channels must be of the same type to compare dates
    # i.e. cannot compare "nightly-2023-10-01" with "beta-2023-10-01"
    return nil unless stability == other.stability

    compare_dates(T.must(date), T.must(other.date))
  end
end

#==(other) ⇒ Object



71
72
73
74
75
# File 'lib/dependabot/rust_toolchain/channel.rb', line 71

def ==(other)
  return false unless other.is_a?(Channel)

  stability == other.stability && date == other.date && version == other.version
end

#channel_typeObject



43
44
45
46
47
48
49
50
# File 'lib/dependabot/rust_toolchain/channel.rb', line 43

def channel_type
  case [!!version, !!(stability && date), !!stability]
  in [true, _, _] then ChannelType::Version
  in [false, true, _] then ChannelType::DatedStability
  in [false, false, true] then ChannelType::Stability
  else ChannelType::Unknown
  end
end

#inspectObject



88
89
90
# File 'lib/dependabot/rust_toolchain/channel.rb', line 88

def inspect
  "#<#{self.class.name} channel=#{stability.inspect} date=#{date.inspect} version=#{version.inspect}>"
end

#to_sObject



78
79
80
81
82
83
84
85
# File 'lib/dependabot/rust_toolchain/channel.rb', line 78

def to_s
  case [version, stability, date]
  in [String => v, _, _] then v
  in [nil, String => c, String => d] then "#{c}-#{d}"
  in [nil, String => c, _] then c
  else "unknown"
  end
end