Class: Encore::Serializer::Base
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- Encore::Serializer::Base
- Defined in:
- lib/encore/serializer/base.rb
Class Method Summary collapse
-
.always_include ⇒ Object
Specify which resources the API always include in the “linked” top-level key.
-
.can_access ⇒ Object
Specify which resources the API exposes URL to.
-
.can_include ⇒ Object
Specify which resources the API can be included in the “linked” top-level key.
- .key_mappings ⇒ Object
- .root_key ⇒ Object
Instance Method Summary collapse
Class Method Details
.always_include ⇒ Object
Specify which resources the API always include in the “linked” top-level key.
31 32 33 |
# File 'lib/encore/serializer/base.rb', line 31 def self.always_include [] end |
.can_access ⇒ Object
Specify which resources the API exposes URL to. Default is can_include + always_include.
37 38 39 |
# File 'lib/encore/serializer/base.rb', line 37 def self.can_access can_include | always_include end |
.can_include ⇒ Object
Specify which resources the API can be included in the “linked” top-level key.
26 27 28 |
# File 'lib/encore/serializer/base.rb', line 26 def self.can_include [] end |
.key_mappings ⇒ Object
45 46 47 |
# File 'lib/encore/serializer/base.rb', line 45 def self.key_mappings {} end |
.root_key ⇒ Object
41 42 43 |
# File 'lib/encore/serializer/base.rb', line 41 def self.root_key model_class.name.pluralize.underscore.to_sym end |
Instance Method Details
#id ⇒ Object
8 9 10 |
# File 'lib/encore/serializer/base.rb', line 8 def id object.id.to_s end |
#links ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/encore/serializer/base.rb', line 12 def links object.reflections.each_with_object({}) do |(_, reflection), memo| if object.association(reflection.name).loaded? fetcher = LinksReflectionIncluder::Loaded else next unless self.class.can_access.include?(reflection.name) fetcher = LinksReflectionIncluder::NotLoaded end memo.merge!(reflection.name => fetcher.send("reflection_#{reflection.macro}", object, reflection)) end end |