Class: Graphiti::Util::SerializerAttribute
- Defined in:
- lib/graphiti/util/serializer_attributes.rb
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(name, attr, resource, serializer, extra) ⇒ SerializerAttribute
constructor
A new instance of SerializerAttribute.
Constructor Details
#initialize(name, attr, resource, serializer, extra) ⇒ SerializerAttribute
Returns a new instance of SerializerAttribute.
4 5 6 7 8 9 10 |
# File 'lib/graphiti/util/serializer_attributes.rb', line 4 def initialize(name, attr, resource, serializer, extra) @name = name @attr = attr @resource = resource @serializer = serializer @extra = extra end |
Instance Method Details
#apply ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graphiti/util/serializer_attributes.rb', line 12 def apply return unless readable? if @name == :id @serializer.id(&proc) elsif @attr[:proc] @serializer.send(_method, @name, , &proc) elsif @serializer.attribute_blocks[@name].nil? @serializer.send(_method, @name, , &proc) else unless @serializer.send(applied_method).include?(@name) inner = @serializer.attribute_blocks.delete(@name) wrapped = wrap_proc(inner) @serializer.send(_method, @name, , &wrapped) end end existing = @serializer.send(applied_method) @serializer.send(:"#{applied_method}=", [@name] | existing) end |