Class: Libis::Workflow::ActiveRecord::Helpers::HashSerializer
- Inherits:
-
Object
- Object
- Libis::Workflow::ActiveRecord::Helpers::HashSerializer
- Defined in:
- lib/libis/workflow/activerecord/helpers/hash_serializer.rb
Class Method Summary collapse
Class Method Details
.dump(hash) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/libis/workflow/activerecord/helpers/hash_serializer.rb', line 11 def self.dump(hash) delete_proc = Proc.new do |_, v| # Cleanup the hash recursively and remove entries with value == nil # noinspection RubyScope v.delete_if(&delete_proc) if v.kind_of?(Hash) v.nil? end hash.delete_if &delete_proc if hash.is_a?(Hash) # Store a nil value if the hash is empty (hash.is_a?(Hash) && !hash.empty?) ? hash : nil end |
.load(hash) ⇒ Object
23 24 25 |
# File 'lib/libis/workflow/activerecord/helpers/hash_serializer.rb', line 23 def self.load(hash) (hash || {}).with_indifferent_access end |