Sha256: 00481653016930e7fbcab9152d47edc2dbca0c5af17aefd97c64c29678b1bb67
Contents?: true
Size: 1.91 KB
Versions: 2
Compression:
Stored size: 1.91 KB
Contents
require 'active_remote/serializers/json' module ActiveRemote module Serialization extend ActiveSupport::Concern included do include Serializers::JSON end module ClassMethods # Serialize the given records into Active Remote objects. # # ====Examples # # records = [ Generic::Remote::TagRequest.new(:name => 'foo') ] # # Tag.serialize_records(records) # => [ Tag#{:name => 'foo'} ] # def serialize_records(records) records.map { |record| instantiate(record.to_hash) } end end # 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(response.errors) # 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 # DEPRECATED – Use :add_errors instead # def add_errors_from_response(response = nil) warn 'DEPRECATED :add_errors_from_response is deprecated and will be removed in Active Remote 3.0. Use :add_errors instead' response ||= last_response add_errors(response.errors) if response.respond_to?(:errors) end # DEPRECATED – Use the class-level :serialize_errors instead # def serialize_records(records = nil) warn 'DEPRECATED Calling :serialize_records on an instance is deprecated and will be removed in Active Remote 3.0. Use the class-level :serialize_records instead' records ||= last_response.records if last_response.respond_to?(:records) return if records.nil? self.class.serialize_records(records) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_remote-2.1.0.beta2 | lib/active_remote/serialization.rb |
active_remote-2.1.0.beta1 | lib/active_remote/serialization.rb |