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 "** Notice: include was renamed to embed_in_root. **\n WARN\n end\n\n @name = name.to_s\n @options = options\n self.embed = options.fetch(:embed) { CONFIG.embed }\n @polymorphic = options.fetch(:polymorphic, false)\n @embed_in_root = options.fetch(:embed_in_root) { options.fetch(:include) { CONFIG.embed_in_root } }\n @key_format = options.fetch(:key_format) { CONFIG.key_format }\n @embed_key = options[:embed_key] || :id\n @key = options[:key]\n @embedded_key = options[:root] || name\n @embed_in_root_key = options.fetch(:embed_in_root_key) { CONFIG.embed_in_root_key }\n @embed_namespace = options.fetch(:embed_namespace) { CONFIG.embed_namespace }\n\n serializer = @options[:serializer]\n @serializer_from_options = serializer.is_a?(String) ? serializer.constantize : serializer\nend\n" |
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 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 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 end |
#embed_key ⇒ Object
Returns the value of attribute embed_key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def 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 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 end |
#embedded_key ⇒ Object
Returns the value of attribute embedded_key.
32 33 34 |
# File 'lib/active_model/serializer/association.rb', line 32 def 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 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 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 () = == :id || == :ids = == :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 |