Sha256: ccb9ec7b0cb926ae88fac6ecc2318fb8f3ba3c69da41f6890efb96f38e64324e

Contents?: true

Size: 1.06 KB

Versions: 52

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module RecordStore
  class Zone
    class Config
      class IgnorePattern
        MATCH_TYPE_FIELD = 'match'
        MATCH_TYPE_REGEX = 'regex'
        MATCH_TYPE_EXACT = 'exact'

        def initialize(orig_hash)
          @orig_hash = orig_hash
        end

        def ignore?(record)
          all_pairs.all? do |(key, value)|
            record.respond_to?(key) && value_matches?(value, record.send(key))
          end
        end

        def to_hash
          @orig_hash
        end

        private

        def all_pairs
          to_hash.reject { |key| key == MATCH_TYPE_FIELD }
        end

        def value_matches?(ignore_pattern_value, record_value)
          return record_value.match?(ignore_pattern_value) if regex?
          return record_value == ignore_pattern_value if exact?

          false
        end

        def regex?
          to_hash[MATCH_TYPE_FIELD] == MATCH_TYPE_REGEX
        end

        def exact?
          to_hash.fetch(MATCH_TYPE_FIELD, MATCH_TYPE_EXACT) == MATCH_TYPE_EXACT
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 1 rubygems

Version Path
record_store-8.0.5 lib/record_store/zone/config/ignore_pattern.rb
record_store-8.0.4 lib/record_store/zone/config/ignore_pattern.rb
record_store-8.0.3 lib/record_store/zone/config/ignore_pattern.rb
record_store-8.0.2 lib/record_store/zone/config/ignore_pattern.rb
record_store-8.0.1 lib/record_store/zone/config/ignore_pattern.rb
record_store-8.0.0 lib/record_store/zone/config/ignore_pattern.rb
record_store-7.1.1 lib/record_store/zone/config/ignore_pattern.rb
record_store-7.1.0 lib/record_store/zone/config/ignore_pattern.rb
record_store-7.0.1 lib/record_store/zone/config/ignore_pattern.rb
record_store-7.0.0 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.7.2 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.7.1 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.7.0 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.6.0 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.5.11 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.5.10 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.5.9 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.5.8 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.5.5 lib/record_store/zone/config/ignore_pattern.rb
record_store-6.5.4 lib/record_store/zone/config/ignore_pattern.rb