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



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

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsHash (readonly)



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

def opts
  @opts
end

Instance Method Details

#default_allow_missing_keyBoolean



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



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



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



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