Sha256: 7825a0c3340b33e1ebe219dcff2a6ec4907ee01bc68a8afa06d30910429481be

Contents?: true

Size: 687 Bytes

Versions: 5

Compression:

Stored size: 687 Bytes

Contents

module Avo
  module Fields
    class StatusField < BaseField
      def initialize(name, **args, &block)
        @defaults = {
          partial_name: 'status-field',
        }

        super(name, **args, &block)

        @loading_when = args[:loading_when].present? ? [args[:loading_when]].flatten : [:waiting, :running]
        @failed_when = args[:failed_when].present? ? [args[:failed_when]].flatten : [:failed]
      end

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

        status
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
avo-0.5.0.beta9 lib/avo/fields/status_field.rb
avo-0.5.0.beta8 lib/avo/fields/status_field.rb
avo-0.5.0.beta7 lib/avo/fields/status_field.rb
avo-0.5.0.beta6 lib/avo/fields/status_field.rb
avo-0.5.0.beta5 lib/avo/fields/status_field.rb