Class: Serega::SeregaConfig::HashAccessConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/config.rb

Overview

Config for the hash_access: attribute option

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Serega::SeregaConfig::HashAccessConfig

Initializes HashAccessConfig object

Parameters:

  • opts (Hash)

    hash_access config options



277
278
279
# File 'lib/serega/config.rb', line 277

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsHash (readonly)

Returns hash_access config options.

Returns:

  • (Hash)

    hash_access config options



268
269
270
# File 'lib/serega/config.rb', line 268

def opts
  @opts
end

Instance Method Details

#default_allow_missing_keyBoolean

Returns allow_missing_key used when an attribute omits it.

Returns:

  • (Boolean)

    allow_missing_key used when an attribute omits it



298
299
300
# File 'lib/serega/config.rb', line 298

def default_allow_missing_key
  opts.fetch(:default_allow_missing_key)
end

#default_allow_missing_key=(value) ⇒ Boolean

Sets the allow_missing_key used when an attribute omits it

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)

    new default allow_missing_key



305
306
307
308
309
310
311
# File 'lib/serega/config.rb', line 305

def default_allow_missing_key=(value)
  unless value == true || value == false
    raise SeregaError, "Invalid hash_access default_allow_missing_key #{value.inspect}. Must be a Boolean"
  end

  opts[:default_allow_missing_key] = value
end

#default_modeSymbol

Returns mode used by hash_access: true (default :symbol).

Returns:

  • (Symbol)

    mode used by hash_access: true (default :symbol)



282
283
284
# File 'lib/serega/config.rb', line 282

def default_mode
  opts.fetch(:default_mode)
end

#default_mode=(value) ⇒ Symbol

Sets the mode used by hash_access: true

Parameters:

  • value (Symbol)

    one of :symbol, :string

Returns:

  • (Symbol)

    new default mode



289
290
291
292
293
294
295
# File 'lib/serega/config.rb', line 289

def default_mode=(value)
  unless AttributeValueResolvers::HashAccessResolver::MODES.include?(value)
    raise SeregaError, "Invalid hash_access default_mode #{value.inspect}. Allowed modes: :symbol, :string"
  end

  opts[:default_mode] = value
end