Module: ActiveRemote::Serialization

Included in:
Base
Defined in:
lib/active_remote/serialization.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
# File 'lib/active_remote/serialization.rb', line 5

def self.included(klass)
  klass.class_eval do
    include ::ActiveRemote::Serializers::JSON
  end
end

Instance Method Details

#add_errors_from_response(response = self.last_response) ⇒ Object

Examine the given response and add any errors to our internal errors list. If no response is given, use the last response.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_remote/serialization.rb', line 14

def add_errors_from_response(response=self.last_response)
  return unless response.respond_to?(:errors)

  response.errors.each do |error|
    if error.respond_to?(:message)
      errors.add(error.field, error.message)
    elsif error.respond_to?(:messages)
      error.messages.each do |message|
        errors.add(error.field, message)
      end
    end
  end
end

#serialize_records ⇒ Object

Examine the last response and serialize any records returned into Active Remote objects.



31
32
33
34
35
36
37
38
39
# File 'lib/active_remote/serialization.rb', line 31

def serialize_records
  return nil unless last_response.respond_to?(:records)

  last_response.records.map do |remote_record|
    record = self.class.allocate
    record.instantiate(remote_record.to_hash)
    record
  end
end