Class: ActiveResource::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/patch.rb

Direct Known Subclasses

ActiveLastfm

Instance Method Summary collapse

Instance Method Details

#load(attributes) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/patch.rb', line 5

def load(attributes)
  raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
  @prefix_options, attributes = split_options(attributes)
  attributes.each do |key, value|
    @attributes[key.to_s] =
      case value
        when Array
          resource = find_or_create_resource_for_collection(key)
#<<<          value.map { |attrs| resource.new(attrs) }
          value.map { |attrs| attrs.is_a?(String) ? attrs.dup : resource.new(attrs) }
        when Hash
          resource = find_or_create_resource_for(key)
          resource.new(value)
        else
          value.dup rescue value
      end
  end
  self
end