lib/adequate_serialization/attribute.rb in adequate_serialization-0.0.1 vs lib/adequate_serialization/attribute.rb in adequate_serialization-0.1.0
- old
+ new
@@ -7,11 +7,11 @@
def initialize(name)
@name = name
end
- def serialize_to(response, model, _includes)
+ def serialize_to(_serializer, response, model, _includes)
response[name] = AdequateSerialization.dump(model.public_send(name))
end
end
class Synthesized
@@ -20,12 +20,13 @@
def initialize(name, &block)
@name = name
@block = block
end
- def serialize_to(response, model, _includes)
- response[name] = AdequateSerialization.dump(block.call(model))
+ def serialize_to(serializer, response, model, _includes)
+ response[name] =
+ AdequateSerialization.dump(serializer.instance_exec(model, &block))
end
end
class IfCondition
attr_reader :attribute, :condition
@@ -33,13 +34,13 @@
def initialize(attribute, condition)
@attribute = attribute
@condition = condition
end
- def serialize_to(response, model, includes)
+ def serialize_to(serializer, response, model, includes)
return unless model.public_send(condition)
- attribute.serialize_to(response, model, includes)
+ attribute.serialize_to(serializer, response, model, includes)
end
end
class UnlessCondition
attr_reader :attribute, :condition
@@ -47,25 +48,25 @@
def initialize(attribute, condition)
@attribute = attribute
@condition = condition
end
- def serialize_to(response, model, includes)
+ def serialize_to(serializer, response, model, includes)
return if model.public_send(condition)
- attribute.serialize_to(response, model, includes)
+ attribute.serialize_to(serializer, response, model, includes)
end
end
class Optional
attr_reader :attribute
def initialize(attribute)
@attribute = attribute
end
- def serialize_to(response, model, includes)
+ def serialize_to(serializer, response, model, includes)
return unless includes.include?(attribute.name)
- attribute.serialize_to(response, model, includes)
+ attribute.serialize_to(serializer, response, model, includes)
end
end
class Config
attr_reader :attribute, :options