Sha256: 0bac393e83285f33373f2c9d2bd9a3ea558d144d4f0a8b94208a2a7d6fde1fc4

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

module RecordStore
  class Zone
    class Config
      include ActiveModel::Validations

      attr_reader :ignore_patterns, :providers, :supports_alias

      validate :validate_zone_config

      def initialize(ignore_patterns: [], providers: nil, supports_alias: nil)
        @ignore_patterns = ignore_patterns.map do |ignore_pattern|
          Zone::Config::IgnorePattern.new(ignore_pattern)
        end

        @providers = providers
        @supports_alias = supports_alias
      end

      def supports_alias?
        if @supports_alias.nil?
          valid_providers? && providers.all? { |provider| Provider.const_get(provider).supports_alias? }
        else
          @supports_alias
        end
      end

      def to_hash
        config_hash = {
          providers: providers,
          ignore_patterns: ignore_patterns.map(&:to_hash),
        }
        config_hash.merge!(supports_alias: supports_alias) if supports_alias

        config_hash
      end

      private

      def validate_zone_config
        errors.add(:providers, 'provider specified does not exist') unless valid_providers?
      end

      def valid_providers?
        providers.present? && providers.all? { |provider| Provider.constants.include?(provider.to_s.to_sym) }
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
record_store-6.1.2 lib/record_store/zone/config.rb
record_store-6.1.1 lib/record_store/zone/config.rb
record_store-6.1.0 lib/record_store/zone/config.rb
record_store-6.0.1 lib/record_store/zone/config.rb
record_store-6.0.0 lib/record_store/zone/config.rb
record_store-5.11.0 lib/record_store/zone/config.rb
record_store-5.10.0 lib/record_store/zone/config.rb
record_store-5.9.0 lib/record_store/zone/config.rb
record_store-5.8.0 lib/record_store/zone/config.rb
record_store-5.7.4 lib/record_store/zone/config.rb
record_store-5.7.3 lib/record_store/zone/config.rb
record_store-5.7.2 lib/record_store/zone/config.rb
record_store-5.7.1 lib/record_store/zone/config.rb
record_store-5.7.0 lib/record_store/zone/config.rb
record_store-5.6.0 lib/record_store/zone/config.rb
record_store-5.5.4 lib/record_store/zone/config.rb