Module: Serega::SeregaConfig::SeregaConfigInstanceMethods

Included in:
Serega::SeregaConfig
Defined in:
lib/serega/config.rb

Overview

SeregaConfig Instance methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optsHash (readonly)

Shows current config as Hash

Returns:

  • (Hash)

    config options



47
48
49
# File 'lib/serega/config.rb', line 47

def opts
  @opts
end

Instance Method Details

#attribute_keysArray<Symbol>

Returns options names allowed in ‘Serega.attribute` method

Returns:

  • (Array<Symbol>)

    Allowed options keys for attribute initialization



76
77
78
# File 'lib/serega/config.rb', line 76

def attribute_keys
  opts.fetch(:attribute_keys)
end

#auto_preloadHash

Returns auto_preload option.

Returns:

  • (Hash)

    auto_preload option



144
145
146
# File 'lib/serega/config.rb', line 144

def auto_preload
  opts.fetch(:auto_preload)
end

#auto_preload=(value) ⇒ Hash

Validates and sets auto_preload option

Returns:

  • (Hash)

    New auto_preload option with attributes that trigger auto preload



150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/serega/config.rb', line 150

def auto_preload=(value)
  opts[:auto_preload] =
    case value
    when true then {has_delegate_option: true, has_serializer_option: true}
    when false then {has_delegate_option: false, has_serializer_option: false}
    when Hash
      SeregaValidations::Utils::CheckAllowedKeys.call(value, %i[has_delegate_option has_serializer_option], "auto_preload")
      {has_delegate_option: !!value[:has_delegate_option], has_serializer_option: !!value[:has_serializer_option]}
    else
      raise SeregaError, "Must have boolean value or Hash, #{value.inspect} provided"
    end
end

#batch_id_optionObject

Returns current batch_id_option



195
196
197
# File 'lib/serega/config.rb', line 195

def batch_id_option
  opts.fetch(:batch_id_option)
end

#batch_id_option=(value) ⇒ Symbol

Sets :batch_id_option config option

Parameters:

  • value (Symbol)

    Set :batch_id_option config option

Returns:

  • (Symbol)

    New :check_attribute_name config option

Raises:



204
205
206
207
# File 'lib/serega/config.rb', line 204

def batch_id_option=(value)
  raise SeregaError, "Must have Symbol value, #{value.inspect} provided" unless value.is_a?(Symbol)
  opts[:batch_id_option] = value
end

#check_attribute_nameObject

Returns whether attributes names check is disabled



180
181
182
# File 'lib/serega/config.rb', line 180

def check_attribute_name
  opts.fetch(:check_attribute_name)
end

#check_attribute_name=(value) ⇒ Boolean

Sets :check_attribute_name config option

Parameters:

  • value (Boolean)

    Set :check_attribute_name config option

Returns:

  • (Boolean)

    New :check_attribute_name config option

Raises:



189
190
191
192
# File 'lib/serega/config.rb', line 189

def check_attribute_name=(value)
  raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false)
  opts[:check_attribute_name] = value
end

#check_initiate_paramsBoolean

Returns :check_initiate_params config option

Returns:

  • (Boolean)

    Current :check_initiate_params config option



88
89
90
# File 'lib/serega/config.rb', line 88

def check_initiate_params
  opts.fetch(:check_initiate_params)
end

#check_initiate_params=(value) ⇒ Boolean

Sets :check_initiate_params config option

Parameters:

  • value (Boolean)

    Set :check_initiate_params config option

Returns:

  • (Boolean)

    :check_initiate_params config option

Raises:



97
98
99
100
# File 'lib/serega/config.rb', line 97

def check_initiate_params=(value)
  raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false)
  opts[:check_initiate_params] = value
end

#delegate_default_allow_nilBoolean

Returns :delegate_default_allow_nil config option

Returns:

  • (Boolean)

    Current :delegate_default_allow_nil config option



104
105
106
# File 'lib/serega/config.rb', line 104

def delegate_default_allow_nil
  opts.fetch(:delegate_default_allow_nil)
end

#delegate_default_allow_nil=(value) ⇒ Boolean

Sets :delegate_default_allow_nil config option

Parameters:

  • value (Boolean)

    Set :delegate_default_allow_nil config option

Returns:

  • (Boolean)

    :delegate_default_allow_nil config option

Raises:



113
114
115
116
# File 'lib/serega/config.rb', line 113

def delegate_default_allow_nil=(value)
  raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false)
  opts[:delegate_default_allow_nil] = value
end

#hide_by_defaultBoolean, Array<Symbol>

Returns :hide_by_default config option

Returns:

  • (Boolean, Array<Symbol>)

    Current :hide_by_default config option



120
121
122
# File 'lib/serega/config.rb', line 120

def hide_by_default
  opts.fetch(:hide_by_default)
end

#hide_by_default=(value) ⇒ Boolean, Array<Symbol>

Sets :hide_by_default config option

Parameters:

  • value (Boolean, Array<Symbol>)

    false, true, or array of :preload/:batch symbols

Returns:

  • (Boolean, Array<Symbol>)

    New :hide_by_default config option



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/serega/config.rb', line 129

def hide_by_default=(value)
  opts[:hide_by_default] =
    case value
    when true, false
      value
    when Array
      invalid = value - %i[preload batch]
      raise SeregaError, "Must have true, false, or an Array of [:preload, :batch], #{value.inspect} provided" if invalid.any?
      value
    else
      raise SeregaError, "Must have true, false, or an Array of [:preload, :batch], #{value.inspect} provided"
    end
end

#initialize(opts = nil) ⇒ Object

Initializes new config instance.

Parameters:

  • opts (Hash) (defaults to: nil)

    Initial config options



54
55
56
57
# File 'lib/serega/config.rb', line 54

def initialize(opts = nil)
  opts ||= DEFAULTS
  @opts = SeregaUtils::EnumDeepDup.call(opts)
end

#initiate_keysArray<Symbol>

Returns options names allowed in ‘Serega#new` method

Returns:

  • (Array<Symbol>)

    allowed options keys



70
71
72
# File 'lib/serega/config.rb', line 70

def initiate_keys
  opts.fetch(:initiate_keys)
end

#max_cached_plans_per_serializer_countBoolean

Returns :max_cached_plans_per_serializer_count config option

Returns:

  • (Boolean)

    Current :max_cached_plans_per_serializer_count config option



165
166
167
# File 'lib/serega/config.rb', line 165

def max_cached_plans_per_serializer_count
  opts.fetch(:max_cached_plans_per_serializer_count)
end

#max_cached_plans_per_serializer_count=(value) ⇒ Boolean

Sets :max_cached_plans_per_serializer_count config option

Parameters:

  • value (Boolean)

    Set :check_initiate_params config option

Returns:

  • (Boolean)

    New :max_cached_plans_per_serializer_count config option

Raises:



174
175
176
177
# File 'lib/serega/config.rb', line 174

def max_cached_plans_per_serializer_count=(value)
  raise SeregaError, "Must have Integer value, #{value.inspect} provided" unless value.is_a?(Integer)
  opts[:max_cached_plans_per_serializer_count] = value
end

#pluginsArray

Shows used plugins

Returns:

  • (Array)

    Used plugins



64
65
66
# File 'lib/serega/config.rb', line 64

def plugins
  opts.fetch(:plugins)
end

#serialize_keysArray<Symbol>

Returns options names allowed in ‘call, to_h` methods

Returns:

  • (Array<Symbol>)

    Allowed options keys for serialization



82
83
84
# File 'lib/serega/config.rb', line 82

def serialize_keys
  opts.fetch(:serialize_keys)
end