Module: HQ::GraphQL::Ext::InputObjectExtensions::InstanceMethods
- Defined in:
- lib/hq/graphql/ext/input_object_extensions.rb
Instance Method Summary collapse
-
#format_nested_attributes ⇒ Object
Recursively format attributes so that they are compatible with ‘accepts_nested_attributes_for`.
Instance Method Details
#format_nested_attributes ⇒ Object
Recursively format attributes so that they are compatible with ‘accepts_nested_attributes_for`
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hq/graphql/ext/input_object_extensions.rb', line 21 def format_nested_attributes self.each.inject({}) do |formatted_attrs, (key, value) | if self.class.nested_attributes.include?(key.to_s) formatted_value = if value.is_a?(Array) value.map(&:format_nested_attributes) elsif value value.format_nested_attributes end formatted_attrs[:"#{key}_attributes"] = formatted_value if formatted_value elsif key.to_s == "x" formatted_attrs[:X] = value else formatted_attrs[key] = value end formatted_attrs end end |