Class: ActiveResource::Base
- Inherits:
-
Object
- Object
- ActiveResource::Base
- Defined in:
- lib/hot_fixes.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#load(attributes, remove_root = false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hot_fixes.rb', line 25 def load(attributes, remove_root = false) raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash) @prefix_options, attributes = (attributes) if attributes.keys.size == 1 remove_root = self.class.element_name == attributes.keys.first.to_s end attributes = Formats.remove_root(attributes) if remove_root attributes.each do |key, value| @attributes[key.to_s] = case value when Array resource = nil value.map do |attrs| if attrs.is_a?(Hash) resource ||= find_or_create_resource_for_collection(key) resource.new(attrs, attrs.has_key?(resource.primary_key.to_s)) else attrs.duplicable? ? attrs.dup : attrs end end when Hash resource = find_or_create_resource_for(key) resource.new(value, value.has_key?(resource.primary_key.to_s)) else value.duplicable? ? value.dup : value end end self end |