Class: GovukPublishingComponents::ApplicationsPage
- Inherits:
-
Object
- Object
- GovukPublishingComponents::ApplicationsPage
- Defined in:
- app/models/govuk_publishing_components/applications_page.rb
Instance Attribute Summary collapse
-
#ruby_version ⇒ Object
readonly
Returns the value of attribute ruby_version.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #gem_version ⇒ Object
-
#initialize(application) ⇒ ApplicationsPage
constructor
A new instance of ApplicationsPage.
- #readable_name ⇒ Object
- #ruby_status(version) ⇒ Object
- #sass_version ⇒ Object
- #yarn_version ⇒ Object
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_version ⇒ Object (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 |
#source ⇒ Object (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_version ⇒ Object
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_name ⇒ Object
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_version ⇒ Object
22 23 24 |
# File 'app/models/govuk_publishing_components/applications_page.rb', line 22 def sass_version parse_file(@gemfilelock, /sass-embedded \(([^)>=~ ]+)\)/) end |
#yarn_version ⇒ Object
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 |