Sha256: b263012ffefccf0ce0f36b12f86c7e952557706fb71a7cf9bf42d4a7d68f70e0

Contents?: true

Size: 682 Bytes

Versions: 6

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

require_relative 'base_checker'
module Checkability
  # Checks if postcode exists in Storage
  #
  class StorageChecker < BaseChecker
    attr_reader :storage_class, :attr_name

    def post_initialize(conf = {})
      @storage_class = conf[:storage_class]
      @attr_name = conf[:attr_name] || :value
    end

    def result(checkable)
      value = _normalize_value(checkable.send(attr_name))
      storage_class.where(attr_name => value).present?
    end

    def message(res, str = nil)
      "#{res}:::Allowed #{storage_class}s list: #{str}"
    end

    private

    def _normalize_value(value)
      value.delete(' ').upcase
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
checkability-2.1.2 lib/checkability/storage_checker.rb
checkability-2.1.1 lib/checkability/storage_checker.rb
checkability-2.1.0 lib/checkability/storage_checker.rb
checkability-2.0.3 lib/checkability/storage_checker.rb
checkability-2.0.2 lib/checkability/storage_checker.rb
checkability-2.0.1 lib/checkability/storage_checker.rb