Class: GovukPublishingComponents::ApplicationsPage

Inherits:
Object
  • Object
show all
Defined in:
app/models/govuk_publishing_components/applications_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ ApplicationsPage

Returns a new instance of ApplicationsPage.



5
6
7
8
9
10
11
12
# File 'app/models/govuk_publishing_components/applications_page.rb', line 5

def initialize(application)
  @application = application
  @dir = get_directory
  @gemfilelock = get_file("Gemfile.lock")
  rubyfile = get_file(".ruby-version")
  @ruby_version = rubyfile.strip if rubyfile
  @packagejson = get_file("package.json")
end

Instance Attribute Details

#ruby_versionObject (readonly)

Returns the value of attribute ruby_version.



3
4
5
# File 'app/models/govuk_publishing_components/applications_page.rb', line 3

def ruby_version
  @ruby_version
end

#sourceObject (readonly)

Returns the value of attribute source.



3
4
5
# File 'app/models/govuk_publishing_components/applications_page.rb', line 3

def source
  @source
end

Instance Method Details

#gem_versionObject



18
19
20
# File 'app/models/govuk_publishing_components/applications_page.rb', line 18

def gem_version
  parse_file(@gemfilelock, /govuk_publishing_components \(([^)>=~ ]+)\)/)
end

#readable_nameObject



14
15
16
# File 'app/models/govuk_publishing_components/applications_page.rb', line 14

def readable_name
  @application.gsub("-", " ").capitalize
end

#ruby_status(version) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/govuk_publishing_components/applications_page.rb', line 26

def ruby_status(version)
  version = version.to_f # to_f ignores non-numbers on the string end, so 3.3.1 becomes 3.1
  versions = [
    {
      version: 3.3,
      eol: "2027-03-31",
    },
    {
      version: 3.2,
      eol: "2026-03-31",
    },
    {
      version: 3.1,
      eol: "2024-04-23",
    },
  ]
  today = Date.today # rubocop:disable Rails/Date
  result = "not set"

  versions.each do |v|
    next unless version >= v[:version]

    version_eol = Date.parse(v[:eol])
    age = version_eol - today
    result = "green"
    result = "orange" if age < 100
    result = "red" if age.negative?
    break
  end

  result
end

#sass_versionObject



22
23
24
# File 'app/models/govuk_publishing_components/applications_page.rb', line 22

def sass_version
  parse_file(@gemfilelock, /sass-embedded \(([^)>=~ ]+)\)/)
end

#yarn_versionObject



59
60
61
# File 'app/models/govuk_publishing_components/applications_page.rb', line 59

def yarn_version
  parse_file(@packagejson, /"packageManager"\s*:\s*"yarn@(\d+(?:\.\d+)*)"/)
end