Class: ActiveModel::Serializer::Association
- Inherits:
-
Object
- Object
- ActiveModel::Serializer::Association
- Defined in:
- lib/active_model/serializer/association.rb,
lib/active_model/serializer/association/has_one.rb,
lib/active_model/serializer/association/has_many.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#embed_ids ⇒ Object
(also: #embed_ids?)
readonly
Returns the value of attribute embed_ids.
-
#embed_in_root ⇒ Object
(also: #embed_in_root?)
Returns the value of attribute embed_in_root.
-
#embed_in_root_key ⇒ Object
(also: #embed_in_root_key?)
Returns the value of attribute embed_in_root_key.
-
#embed_key ⇒ Object
Returns the value of attribute embed_key.
-
#embed_namespace ⇒ Object
(also: #embed_namespace?)
Returns the value of attribute embed_namespace.
-
#embed_objects ⇒ Object
(also: #embed_objects?)
readonly
Returns the value of attribute embed_objects.
-
#embedded_key ⇒ Object
Returns the value of attribute embedded_key.
-
#key ⇒ Object
Returns the value of attribute key.
-
#key_format ⇒ Object
Returns the value of attribute key_format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#polymorphic ⇒ Object
(also: #polymorphic?)
readonly
Returns the value of attribute polymorphic.
-
#root_key ⇒ Object
Returns the value of attribute root_key.
-
#serializer_from_options ⇒ Object
Returns the value of attribute serializer_from_options.
Instance Method Summary collapse
- #build_serializer(object, options = {}) ⇒ Object
- #default_serializer ⇒ Object
- #embed=(embed) ⇒ Object
-
#initialize(name, options = {}) ⇒ Association
constructor
A new instance of Association.
- #serializer_from_object(object, options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Association
Returns a new instance of Association.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_model/serializer/association.rb', line 8 def initialize(name, ={}) if .has_key?(:include) ActiveSupport::Deprecation.warn <<-WARN ** Notice: include was renamed to embed_in_root. ** WARN end @name = name.to_s @options = self. = .fetch(:embed) { CONFIG. } @polymorphic = .fetch(:polymorphic, false) @embed_in_root = .fetch(:embed_in_root) { .fetch(:include) { CONFIG. } } @key_format = .fetch(:key_format) { CONFIG.key_format } @embed_key = [:embed_key] || :id @key = [:key] @embedded_key = [:root] || name @embed_in_root_key = .fetch(:embed_in_root_key) { CONFIG. } @embed_namespace = .fetch(:embed_namespace) { CONFIG. } serializer = @options[:serializer] @serializer_from_options = serializer.is_a?(String) ? serializer.constantize : serializer end |
Instance Attribute Details
#embed_ids ⇒ Object (readonly) Also known as: embed_ids?
Returns the value of attribute embed_ids.
31 32 33 |
# File 'lib/active_model/serializer/association.rb', line 31 def @embed_ids end |
#embed_in_root ⇒ Object Also known as: embed_in_root?
Returns the value of attribute embed_in_root.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @embed_in_root end |
#embed_in_root_key ⇒ Object Also known as: embed_in_root_key?
Returns the value of attribute embed_in_root_key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @embed_in_root_key end |
#embed_key ⇒ Object
Returns the value of attribute embed_key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @embed_key end |
#embed_namespace ⇒ Object Also known as: embed_namespace?
Returns the value of attribute embed_namespace.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @embed_namespace end |
#embed_objects ⇒ Object (readonly) Also known as: embed_objects?
Returns the value of attribute embed_objects.
31 32 33 |
# File 'lib/active_model/serializer/association.rb', line 31 def @embed_objects end |
#embedded_key ⇒ Object
Returns the value of attribute embedded_key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @embedded_key end |
#key ⇒ Object
Returns the value of attribute key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def key @key end |
#key_format ⇒ Object
Returns the value of attribute key_format.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def key_format @key_format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/active_model/serializer/association.rb', line 31 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @options end |
#polymorphic ⇒ Object (readonly) Also known as: polymorphic?
Returns the value of attribute polymorphic.
31 32 33 |
# File 'lib/active_model/serializer/association.rb', line 31 def polymorphic @polymorphic end |
#root_key ⇒ Object
Returns the value of attribute root_key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def root_key @root_key end |
#serializer_from_options ⇒ Object
Returns the value of attribute serializer_from_options.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def @serializer_from_options end |
Instance Method Details
#build_serializer(object, options = {}) ⇒ Object
53 54 55 |
# File 'lib/active_model/serializer/association.rb', line 53 def build_serializer(object, = {}) serializer_class(object, ).new(object, .merge(self.)) end |
#default_serializer ⇒ Object
49 50 51 |
# File 'lib/active_model/serializer/association.rb', line 49 def default_serializer DefaultSerializer end |
#embed=(embed) ⇒ Object
40 41 42 43 |
# File 'lib/active_model/serializer/association.rb', line 40 def () @embed_ids = == :id || == :ids @embed_objects = == :object || == :objects end |
#serializer_from_object(object, options = {}) ⇒ Object
45 46 47 |
# File 'lib/active_model/serializer/association.rb', line 45 def serializer_from_object(object, = {}) Serializer.serializer_for(object, ) end |