Class: ActiveModel::Serializer::Association::HasOne

Inherits:
ActiveModel::Serializer::Association show all
Defined in:
lib/active_model/serializer/associations.rb

Instance Attribute Summary

Attributes inherited from ActiveModel::Serializer::Association

#embed_ids, #embed_in_root, #embed_in_root_key, #embed_key, #embed_namespace, #embed_objects, #embedded_key, #key, #key_format, #name, #options, #root_key, #serializer_from_options

Instance Method Summary collapse

Methods inherited from ActiveModel::Serializer::Association

#default_serializer, #embed=, #serializer_from_object

Constructor Details

#initialize(name, *args) ⇒ HasOne

Returns a new instance of HasOne.



54
55
56
57
58
# File 'lib/active_model/serializer/associations.rb', line 54

def initialize(name, *args)
  super
  @root_key = @embedded_key.to_s.pluralize
  @key ||= "#{name}_id"
end

Instance Method Details

#build_serializer(object, options = {}) ⇒ Object



64
65
66
67
# File 'lib/active_model/serializer/associations.rb', line 64

def build_serializer(object, options = {})
  options[:_wrap_in_array] = embed_in_root?
  super
end

#serializer_class(object) ⇒ Object



60
61
62
# File 'lib/active_model/serializer/associations.rb', line 60

def serializer_class(object)
  serializer_from_options || serializer_from_object(object) || default_serializer
end