Sha256: ed2bd71bc2f53025aca532fbfcd62276c3c84cdd0440250dbe2cc2f2146c2a09
Contents?: true
Size: 697 Bytes
Versions: 40
Compression:
Stored size: 697 Bytes
Contents
require 'locomotive/coal' module Locomotive::Wagon module ToHashConcern def to_hash {}.tap do |hash| __attributes__.each do |name| value = self.public_send(name) next if value.nil? hash[name] = prepare_value_for_hash(value) end end end def prepare_value_for_hash(value) if value.is_a?(Array) && value.any? { |v| v.respond_to?(:__attributes__) } value.map(&:to_hash) elsif value.is_a?(Array) && value.empty? nil # reset the array elsif value.respond_to?(:translations) !value.translations.empty? ? value.translations : nil else value end end end end
Version data entries
40 entries across 40 versions & 1 rubygems