Sha256: afda818a66dcb6aaaac1914bf526a66018d830e4fb1a1be4abddfb2c9d4f188b

Contents?: true

Size: 693 Bytes

Versions: 6

Compression:

Stored size: 693 Bytes

Contents

module ActiveModel
  class Serializer
    class Association
      class HasOne < Association
        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

        def serializer_class(object, options = {})
          (serializer_from_options unless object.nil?) || serializer_from_object(object, options) || default_serializer
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_model_serializers-0.9.9 lib/active_model/serializer/association/has_one.rb
active_model_serializers-0.9.8 lib/active_model/serializer/association/has_one.rb
active_model_serializers-0.9.7 lib/active_model/serializer/association/has_one.rb
active_model_serializers-0.9.6 lib/active_model/serializer/association/has_one.rb
active_model_serializers-0.9.5 lib/active_model/serializer/association/has_one.rb
active_model_serializers-0.9.4 lib/active_model/serializer/association/has_one.rb