Sha256: eaf51bb7adbad501b89e9c15b33b4f3ac0726cbcbd593885b13a25e68b204640

Contents?: true

Size: 871 Bytes

Versions: 2

Compression:

Stored size: 871 Bytes

Contents

module LIVR
  module Rules
    module Common

      class Required < Rule
        def call(value, user_data, field_results)
          return if value.in?([[], {}])
          "REQUIRED" if value.blank?
        end
      end

      class NotEmpty < Rule
        def call(value, user_data, field_results)
          "CANNOT_BE_EMPTY" if value == ""
        end
      end

      class NotEmptyList < Rule
        def call(list, user_data, field_results)
          return "CANNOT_BE_EMPTY" if is_no_value(list)
          return "CANNOT_BE_EMPTY" if list.is_a?(Array) && list.blank?
          return "FORMAT_ERROR" unless list.is_a?(Array)
        end
      end

      class AnyObject < Rule
        def call(value, user_data, field_results)
          return if is_no_value(value)
          return "FORMAT_ERROR" unless value.is_a?(Hash)
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
ruby-livr-2.0.0 lib/livr/rules/common.rb
livr2-2.0.0 lib/livr/rules/common.rb