Module: Deimos::SharedConfig::ClassMethods

Defined in:
lib/deimos/shared_config.rb

Overview

need to use this instead of class_methods to be backwards-compatible with Rails 3

Instance Method Summary collapse

Instance Method Details

#configHash

Returns:

  • (Hash)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/deimos/shared_config.rb', line 14

def config
  return @config if @config

  # default to none: true
  @config = {
    key_configured: false,
    encode_key: false,
    no_keys: 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

#key_config(plain: nil, field: nil, schema: nil, none: nil) ⇒ void

This method returns an undefined value.

Set key configuration.

Parameters:

  • field (Symbol) (defaults to: nil)

    the name of a field to use in the value schema as a generated key schema

  • schema (String, Symbol) (defaults to: nil)

    the name of a schema to use for the key

  • plain (Boolean) (defaults to: nil)

    if true, do not encode keys at all

  • none (Boolean) (defaults to: nil)

    if true, do not use keys at all



57
58
59
60
61
62
63
# File 'lib/deimos/shared_config.rb', line 57

def key_config(plain: nil, field: nil, schema: nil, none: nil)
  config[:key_configured] = true
  config[:no_keys] = none
  config[:encode_key] = !plain && !none
  config[:key_field] = field&.to_s
  config[:key_schema] = schema
end

#namespace(namespace) ⇒ void

This method returns an undefined value.

Set the namespace.

Parameters:

  • namespace (String)


46
47
48
# File 'lib/deimos/shared_config.rb', line 46

def namespace(namespace)
  config[:namespace] = namespace
end

#schema(schema) ⇒ void

This method returns an undefined value.

Set the schema.

Parameters:

  • schema (String)


39
40
41
# File 'lib/deimos/shared_config.rb', line 39

def schema(schema)
  config[:schema] = schema
end

#schema_class_config(use_schema_classes) ⇒ void

This method returns an undefined value.

Parameters:

  • use_schema_classes (Boolean)


67
68
69
# File 'lib/deimos/shared_config.rb', line 67

def schema_class_config(use_schema_classes)
  config[:use_schema_classes] = use_schema_classes
end