31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/query_helper/associations.rb', line 31
def self.json_associations(associations)
associations ||= []
associations = associations.is_a?(Array) ? associations : [associations]
associations.inject([]) do |translated, association|
if association.is_a?(Symbol) || association.is_a?(String)
translated << association.to_sym
elsif association.is_a?(Array)
translated << association.map(&:to_sym)
elsif association.is_a?(Hash)
translated_hash = {}
association.each do |key, value|
translated_hash[key.to_sym] = { include: json_associations(value) }
end
translated << translated_hash
end
end
end
|