Sha256: e1dae57e1ab50680af730ea57894a7ed855f9ebfe79dd2b08b412d71ba91a7b4

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'active_support/concern' # Missing on "eac/listable"
require 'active_support/hash_with_indifferent_access'
require 'eac_ruby_utils/listable'

module EacLauncher
  module Publish
    class CheckResult
      include ::EacRubyUtils::Listable

      lists.add_string :status, :updated, :pending, :blocked, :outdated

      lists.status.values.each do |status|
        class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
          def self.#{status}(message)
            new('#{status}', message)
          end
        RUBY_EVAL
      end

      class << self
        def pending_status?(status)
          [STATUS_PENDING].include?(status)
        end

        def updated_color
          'green'
        end

        def pending_color
          'yellow'
        end

        def blocked_color
          'red'
        end

        def outdated_color
          'light_blue'
        end
      end

      attr_reader :status, :message

      def initialize(status, message)
        raise "Status \"#{status}\" not in #{self.class.lists.status.values}" unless
        self.class.lists.status.values.include?(status)

        @status = status
        @message = message
      end

      def to_s
        message.light_white.send("on_#{background_color}")
      end

      private

      def background_color
        self.class.send("#{status}_color")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eac_launcher-0.6.8 lib/eac_launcher/publish/check_result.rb
eac_launcher-0.6.7 lib/eac_launcher/publish/check_result.rb
eac_launcher-0.6.6 lib/eac_launcher/publish/check_result.rb