Class: ActiveModel::Serializer::Association::HasOne
- Inherits:
-
ActiveModel::Serializer::Association
- Object
- ActiveModel::Serializer::Association
- ActiveModel::Serializer::Association::HasOne
- Defined in:
- lib/active_model/serializer/association/has_one.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, #polymorphic, #root_key, #serializer_from_options
Instance Method Summary collapse
- #build_serializer(object, options = {}) ⇒ Object
-
#initialize(name, *args) ⇒ HasOne
constructor
A new instance of HasOne.
- #serializer_class(object, options = {}) ⇒ Object
Methods inherited from ActiveModel::Serializer::Association
#default_serializer, #embed=, #serializer_from_object
Constructor Details
#initialize(name, *args) ⇒ HasOne
Returns a new instance of HasOne.
5 6 7 8 9 10 11 12 |
# File 'lib/active_model/serializer/association/has_one.rb', line 5 def initialize(name, *args) super @root_key = @embedded_key.to_s.pluralize @key ||= case CONFIG.default_key_type when :name then name.to_s.singularize else "#{name}_id" end end |
Instance Method Details
#build_serializer(object, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/active_model/serializer/association/has_one.rb', line 18 def build_serializer(object, = {}) [:_wrap_in_array] = super end |
#serializer_class(object, options = {}) ⇒ Object
14 15 16 |
# File 'lib/active_model/serializer/association/has_one.rb', line 14 def serializer_class(object, = {}) ( unless object.nil?) || serializer_from_object(object, ) || default_serializer end |