Class: Dev::EndOfLife::ProductVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/firespring_dev_commands/eol/product_version.rb

Overview

Class which tracks a specific product and provides methods for determining the end of life date

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cycle, description = nil) ⇒ ProductVersion

Returns a new instance of ProductVersion.



9
10
11
12
13
14
15
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 9

def initialize(name, cycle, description = nil)
  @name = name
  @cycle = cycle
  @eol_date = nil
  @eol = nil
  @description = description
end

Instance Attribute Details

#cycleObject

Returns the value of attribute cycle.



7
8
9
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 7

def cycle
  @cycle
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 7

def description
  @description
end

#eolObject

Returns whether this product version is currently EOL



23
24
25
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 23

def eol
  @eol
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 7

def name
  @name
end

Instance Method Details

#eol_dateObject

Returns the date at which this product is EOL



29
30
31
32
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 29

def eol_date
  populate_eol_info unless @eol_date
  @eol_date
end

#populate_eol_infoObject

Populates the eol and eol_date values If eol is a boolean then the eol_date will be set to nil



36
37
38
39
40
41
42
43
44
45
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 36

def populate_eol_info
  detail = product_detail(name, cycle)
  eol = detail['eol']
  if eol.boolean?
    @eol = eol
  else
    @eol_date = Date.parse(eol)
    @eol = @eol_date < Date.today
  end
end

Print the status information for the product with additional coloring to show eol status



18
19
20
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 18

def print_status
  puts to_s_colorize
end

#product_detail(product, cycle) ⇒ Object

Returns the product details for the product and cycle based off the api response and any manually configured dates



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 48

def product_detail(product, cycle)
  detail = {}

  uri = URI.parse("#{END_OF_LIFE_API_URL}/#{product}/#{cycle}.json")
  response = Net::HTTP.get_response(uri)
  detail = JSON.parse(response.body) if response.is_a?(Net::HTTPSuccess)

  # If EOL info is a boolean or missing from the current details, overwrite with the manual date (if present)
  manual_date = Dev::EndOfLife.config.manual_dates["#{product}_#{cycle.tr('.', '_')}".to_sym]
  detail['eol'] = manual_date if manual_date && (detail['eol'].boolean? || detail['eol'].nil?)
  detail['eol'] = '1979-01-01' if detail.empty?
  detail
end

#to_sObject

Returns a string representation of the product and its eol status



63
64
65
66
67
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 63

def to_s
  message = "  #{name} (#{cycle}) is EOL on #{eol_date || 'n/a'}"
  message << " (#{(eol_date - Date.today).to_i} days)" if eol_date
  format '%-60s %s', message, description
end

#to_s_colorizeObject

Returns the string representation of the product with additional coloring



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/firespring_dev_commands/eol/product_version.rb', line 70

def to_s_colorize
  return to_s.light_red if eol

  if eol_date
    return to_s.light_green if eol_date > (Date.today + 240)
    return to_s.light_yellow if eol_date > (Date.today + 60)

    return to_s.light_magenta
  end

  to_s.light_white
end