Sha256: 9bea4b459ea76f134e4a8660dcb9f212c0d51e86761f0aef7eeb9db8f8d448e8

Contents?: true

Size: 1.15 KB

Versions: 23

Compression:

Stored size: 1.15 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
        @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,
        }
        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

23 entries across 23 versions & 1 rubygems

Version Path
record_store-5.2.1 lib/record_store/zone/config.rb
record_store-5.2.0 lib/record_store/zone/config.rb
record_store-5.1.1 lib/record_store/zone/config.rb
record_store-5.1.0 lib/record_store/zone/config.rb
record_store-5.0.5 lib/record_store/zone/config.rb
record_store-5.0.4 lib/record_store/zone/config.rb
record_store-5.0.3 lib/record_store/zone/config.rb
record_store-5.0.2 lib/record_store/zone/config.rb
record_store-5.0.1 lib/record_store/zone/config.rb
record_store-5.0.0 lib/record_store/zone/config.rb
record_store-4.0.7 lib/record_store/zone/config.rb
record_store-4.0.6 lib/record_store/zone/config.rb
record_store-4.0.5 lib/record_store/zone/config.rb
record_store-4.0.4 lib/record_store/zone/config.rb
record_store-4.0.3 lib/record_store/zone/config.rb
record_store-4.0.2 lib/record_store/zone/config.rb
record_store-4.0.1 lib/record_store/zone/config.rb
record_store-4.0.0 lib/record_store/zone/config.rb
record_store-3.1.4 lib/record_store/zone/config.rb
record_store-3.1.3 lib/record_store/zone/config.rb