module ActiveModel::Serializer::IncludeTree::Parsing
def include_args_to_hash(included)
-
(Hash)
- a Hash representing the same tree structure
Parameters:
-
included
(Symbol, Hash, Array, String
) --
def include_args_to_hash(included) case included when Symbol { included => {} } when Hash included.each_with_object({}) do |(key, value), hash| hash[key] = include_args_to_hash(value) end when Array included.reduce({}) { |a, e| a.deep_merge!(include_args_to_hash(e)) } when String include_string_to_hash(included) else {} end end
def include_string_to_hash(included)
-
(Hash)
- a Hash representing the same tree structure
Parameters:
-
included
(String
) --
def include_string_to_hash(included) # TODO: Needs comment walking through the process of what all this is doing. included.delete(' ').split(',').reduce({}) do |hash, path| include_tree = path.split('.').reverse_each.reduce({}) { |a, e| { e.to_sym => a } } hash.deep_merge!(include_tree) end end