class CriterionDecorator

Public Class Methods

overall_status(criteria) click to toggle source
# File lib/aptible/rails/decorators/criterion_decorator.rb, line 2
def self.overall_status(criteria)
  return 'red' if criteria.any? { |c| c.status == 'red' }
  return 'yellow' if criteria.any? { |c| c.status == 'yellow' }
  'green'
end
status_description(status) click to toggle source
# File lib/aptible/rails/decorators/criterion_decorator.rb, line 8
def self.status_description(status)
  case status
  when 'red' then 'Not Compliant'
  when 'green' then 'Compliant'
  when 'yellow' then 'Needs Review'
  end
end

Public Instance Methods

current_document() click to toggle source
# File lib/aptible/rails/decorators/criterion_decorator.rb, line 51
def current_document
  documents.first
end
status_description() click to toggle source
# File lib/aptible/rails/decorators/criterion_decorator.rb, line 16
def status_description
  self.class.status_description(object.status)
end
unique_app_count() click to toggle source
# File lib/aptible/rails/decorators/criterion_decorator.rb, line 43
def unique_app_count
  valid_documents.map { |d| d.links['app'].href }.uniq.count
end
unique_user_count() click to toggle source

rubocop:enable MethodLength

# File lib/aptible/rails/decorators/criterion_decorator.rb, line 39
def unique_user_count
  valid_documents.map { |d| d.links['user'].href }.uniq.count
end
update_summary() click to toggle source

rubocop:disable MethodLength

# File lib/aptible/rails/decorators/criterion_decorator.rb, line 21
def update_summary
  case object.scope
  when 'organization'
    if current_document
      "Updated #{h.time_ago_in_words(current_document.created_at)} ago"
    else
      'Never updated'
    end
  when 'app'
    count = unique_app_count
    "Completed for #{count} #{'app'.pluralize(count)}"
  when 'user'
    count = unique_user_count
    "Completed for #{count} #{'user'.pluralize(count)}"
  end
end
valid_documents() click to toggle source
# File lib/aptible/rails/decorators/criterion_decorator.rb, line 47
def valid_documents
  object.documents.select { |d| d.expires_at.nil? || d.expires_at > Time.now }
end