Module: ActiveRemote::Serialization

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_remote/serialization.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_errors(errors) ⇒ Object

Add the given errors to our internal errors list

Examples

response = remote_call(:action_that_returns_errors, { :stuff => 'foo' })

add_errors(response.errors)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_remote/serialization.rb', line 33

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

#add_errors_from_response(response = nil) ⇒ Object

Examine the given response and add any errors to our internal errors list.

Examples

response = remote_call(:action_that_returns_errors, { :stuff => 'foo' })

add_errors_from_response(response)


54
55
56
57
58
59
60
61
# File 'lib/active_remote/serialization.rb', line 54

def add_errors_from_response(response = nil)
  unless response
    warn 'DEPRECATED calling Model#add_errors_from_response without args is deprecated and will be removed in Active Remote 3.0.'
    response = last_response
  end

  add_errors(response.errors) if response.respond_to?(:errors)
end

#serialize_records(records = nil) ⇒ Object

DEPRECATED – Use the class-level :serialize_errors instead



65
66
67
68
69
70
71
72
# File 'lib/active_remote/serialization.rb', line 65

def serialize_records(records = nil)
  warn 'DEPRECATED Calling Model#serialize_records is deprecated and will be removed in Active Remote 3.0. Use Model.serialize_records instead'

  records ||= last_response.records if last_response.respond_to?(:records)
  return if records.nil?

  self.class.serialize_records(records)
end