lib/adequate_serialization/attribute.rb in adequate_serialization-0.1.1 vs lib/adequate_serialization/attribute.rb in adequate_serialization-1.0.0
- old
+ new
@@ -1,8 +1,18 @@
# frozen_string_literal: true
module AdequateSerialization
+ def self.dump(object)
+ if object.is_a?(Hash)
+ object
+ elsif object.respond_to?(:as_json)
+ object.as_json
+ else
+ object
+ end
+ end
+
module Attribute
class Simple
attr_reader :name
def initialize(name)
@@ -36,10 +46,11 @@
@condition = condition
end
def serialize_to(serializer, response, model, includes)
return unless model.public_send(condition)
+
attribute.serialize_to(serializer, response, model, includes)
end
end
class UnlessCondition
@@ -50,10 +61,11 @@
@condition = condition
end
def serialize_to(serializer, response, model, includes)
return if model.public_send(condition)
+
attribute.serialize_to(serializer, response, model, includes)
end
end
class Optional
@@ -63,9 +75,10 @@
@attribute = attribute
end
def serialize_to(serializer, response, model, includes)
return unless includes.include?(attribute.name)
+
attribute.serialize_to(serializer, response, model, includes)
end
end
class Config