Class: RailsSettings::Fields::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/rails-settings/fields/hash.rb

Constant Summary

Constants inherited from Base

Base::SEPARATOR_REGEXP

Instance Attribute Summary

Attributes inherited from Base

#default, #key, #options, #parent, #readonly, #scope, #separator, #type

Instance Method Summary collapse

Methods inherited from Base

#default_value, generate, #initialize, #read, #save!, #saved_value, #table_exists?, #to_h

Constructor Details

This class inherits a constructor from RailsSettings::Fields::Base

Instance Method Details

#deserialize(value) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rails-settings/fields/hash.rb', line 4

def deserialize(value)
  return nil if value.nil?

  return value unless value.is_a?(::String)

  load_value(value).deep_stringify_keys.with_indifferent_access
end

#load_value(value) ⇒ Object



16
17
18
19
20
# File 'lib/rails-settings/fields/hash.rb', line 16

def load_value(value)
  YAML.safe_load(value).to_h
rescue StandardError
  {}
end

#serialize(value) ⇒ Object



12
13
14
# File 'lib/rails-settings/fields/hash.rb', line 12

def serialize(value)
  deserialize(value)
end