Sha256: 24b027100faf8e4bb9547fbc84a60b301bbc3f3ae6504defaec6df2391c85e74

Contents?: true

Size: 1.72 KB

Versions: 17

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

require 'active_support/concern'

module Deimos
  # Module that producers and consumers can share which sets up configuration.
  module SharedConfig
    extend ActiveSupport::Concern

    # need to use this instead of class_methods to be backwards-compatible
    # with Rails 3
    module ClassMethods
      # @return [Hash]
      def config
        return @config if @config

        @config = {
          encode_key: true
        }
        klass = self.superclass
        while klass.respond_to?(:config)
          klass_config = klass.config
          if klass_config
            # default is true for this so don't include it in the merge
            klass_config.delete(:encode_key) if klass_config[:encode_key]
            @config.merge!(klass_config) if klass.config
          end
          klass = klass.superclass
        end
        @config
      end

      # Set the schema.
      # @param schema [String]
      def schema(schema)
        config[:schema] = schema
      end

      # Set the namespace.
      # @param namespace [String]
      def namespace(namespace)
        config[:namespace] = namespace
      end

      # Set key configuration.
      # @param field [Symbol] the name of a field to use in the value schema as
      #   a generated key schema
      # @param schema [String|Symbol] the name of a schema to use for the key
      # @param plain [Boolean] if true, do not encode keys at all
      # @param none [Boolean] if true, do not use keys at all
      def key_config(plain: nil, field: nil, schema: nil, none: nil)
        config[:no_keys] = none
        config[:encode_key] = !plain && !none
        config[:key_field] = field&.to_s
        config[:key_schema] = schema
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
deimos-ruby-1.3.0.pre.beta1 lib/deimos/shared_config.rb
deimos-ruby-1.2.0.pre.beta1 lib/deimos/shared_config.rb
deimos-ruby-1.1.0.pre.beta2 lib/deimos/shared_config.rb
deimos-ruby-1.1.0.pre.beta1 lib/deimos/shared_config.rb
deimos-ruby-1.0.0 lib/deimos/shared_config.rb
deimos-ruby-1.0.0.pre.beta26 lib/deimos/shared_config.rb
deimos-ruby-1.0.0.pre.beta25 lib/deimos/shared_config.rb
deimos-ruby-1.0.0.pre.beta24 lib/deimos/shared_config.rb
deimos-ruby-1.0.0.pre.beta23 lib/deimos/shared_config.rb
deimos-ruby-1.0.0.pre.beta22 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta21 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta20 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta19 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta18 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta17 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta16 lib/deimos/shared_config.rb
deimos-kafka-1.0.0.pre.beta15 lib/deimos/shared_config.rb