Class: ActiveModel::Serializer
- Inherits:
-
Object
- Object
- ActiveModel::Serializer
- Defined in:
- lib/freedom_patches/ams_include_without_root.rb
Direct Known Subclasses
ApplicationSerializer, FlaggedTopicSerializer, FlaggedTopicSummarySerializer
Instance Method Summary collapse
-
#include!(name, options = {}) ⇒ Object
This method is copied over verbatim from the AMS version, except for silently ignoring associations that cannot be embedded without a root instead of raising an exception.
Instance Method Details
#include!(name, options = {}) ⇒ Object
This method is copied over verbatim from the AMS version, except for silently ignoring associations that cannot be embedded without a root instead of raising an exception.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/freedom_patches/ams_include_without_root.rb', line 13 def include!(name, = {}) unique_values = if hash = [:hash] if @options[:hash] == hash @options[:unique_values] ||= {} else {} end else hash = @options[:hash] @options[:unique_values] ||= {} end node = [:node] ||= @node value = [:value] if [:include] == nil if @options.key?(:include) [:include] = @options[:include].include?(name) elsif @options.include?(:exclude) [:include] = !@options[:exclude].include?(name) end end association_class = if klass = _associations[name] klass elsif value.respond_to?(:to_ary) Associations::HasMany else Associations::HasOne end association = association_class.new(name, self, ) if association. node[association.key] = association.serialize_ids if association. && hash.nil? # Don't raise an error! elsif association. && association. merge_association hash, association.root, association.serializables, unique_values end elsif association. node[association.key] = association.serialize end end |