Class: AcidicJob::Serializers::NewRecordSerializer

Inherits:
ActiveJob::Serializers::ObjectSerializer
  • Object
show all
Defined in:
lib/acidic_job/serializers/new_record_serializer.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(hash) ⇒ Object



15
16
17
18
# File 'lib/acidic_job/serializers/new_record_serializer.rb', line 15

def deserialize(hash)
  new_record_class = hash["class"].constantize
  new_record_class.new(hash["attributes"])
end

#serialize(new_record) ⇒ Object



8
9
10
11
12
13
# File 'lib/acidic_job/serializers/new_record_serializer.rb', line 8

def serialize(new_record)
  super(
    "class" => new_record.class.name,
    "attributes" => new_record.attributes
  )
end

#serialize?(argument) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/acidic_job/serializers/new_record_serializer.rb', line 20

def serialize?(argument)
  defined?(::ActiveRecord) && argument.respond_to?(:new_record?) && argument.new_record?
end