Sha256: 49ce4b175ada2cc457867f2e12a2e009ab428a5a9fc7c7f9ee49f5940a14f5ec

Contents?: true

Size: 896 Bytes

Versions: 35

Compression:

Stored size: 896 Bytes

Contents

module Avo
  module Fields
    class StatusField < BaseField
      def initialize(id, **args, &block)
        super(id, **args, &block)

        @loading_when = args[:loading_when].present? ? [args[:loading_when]].flatten.map(&:to_sym) : [:waiting, :running]
        @failed_when = args[:failed_when].present? ? [args[:failed_when]].flatten.map(&:to_sym) : [:failed]
        @success_when = args[:success_when].present? ? [args[:success_when]].flatten.map(&:to_sym) : []
      end

      def status
        status = "neutral"
        if value.present?
          status = "failed" if @failed_when.include? value.to_sym
          status = "loading" if @loading_when.include? value.to_sym
          status = "success" if @success_when.include? value.to_sym
        end

        status
      end

      def options_for_filter
        [@failed_when, @loading_when].flatten
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
avo-3.0.1.beta23 lib/avo/fields/status_field.rb
avo-3.0.1.beta20 lib/avo/fields/status_field.rb
avo-3.0.1.beta21 lib/avo/fields/status_field.rb
avo-3.0.1.beta17 lib/avo/fields/status_field.rb
avo-3.0.1.beta22 lib/avo/fields/status_field.rb
avo-3.0.1.beta18 lib/avo/fields/status_field.rb
avo-3.0.1.beta19 lib/avo/fields/status_field.rb
avo-3.0.1.beta24 lib/avo/fields/status_field.rb
avo-3.0.1.beta15 lib/avo/fields/status_field.rb
avo-3.0.1.beta16 lib/avo/fields/status_field.rb
avo-3.0.1.beta14 lib/avo/fields/status_field.rb
avo-3.0.1.beta12 lib/avo/fields/status_field.rb
avo-3.0.1.beta13 lib/avo/fields/status_field.rb
avo-3.0.1.beta10 lib/avo/fields/status_field.rb
avo-3.0.1.beta11 lib/avo/fields/status_field.rb
avo-3.0.0.pre19 lib/avo/fields/status_field.rb
avo-3.0.1.beta8 lib/avo/fields/status_field.rb
avo-3.0.1.beta9 lib/avo/fields/status_field.rb
avo-3.0.1.beta6 lib/avo/fields/status_field.rb
avo-3.0.1.beta7 lib/avo/fields/status_field.rb