Class: ActiveModelSerializers::Adapter::Base
- Inherits:
-
Object
- Object
- ActiveModelSerializers::Adapter::Base
- Defined in:
- lib/active_model_serializers/adapter/base.rb
Direct Known Subclasses
ActiveModel::Serializer::Adapter::Base, Attributes, Json, JsonApi, Null
Instance Attribute Summary collapse
-
#instance_options ⇒ Object
readonly
Returns the value of attribute instance_options.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Class Method Summary collapse
- .cache_key ⇒ Object
-
.default_key_transform ⇒ Symbol
Sets the default transform for the adapter.
- .fragment_cache(cached_hash, non_cached_hash) ⇒ Object
-
.inherited(subclass) ⇒ Object
Automatically register adapters when subclassing.
-
.transform(options) ⇒ Symbol
Determines the transform to use in order of precedence: adapter option, global config, adapter default.
-
.transform_key_casing!(value, options) ⇒ Symbol
Transforms the casing of the supplied value.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #cache_key ⇒ Object
- #fragment_cache(cached_hash, non_cached_hash) ⇒ Object
-
#initialize(serializer, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#serializable_hash(_options = nil) ⇒ Object
Subclasses that implement this method must first call options = serialization_options(options).
Constructor Details
#initialize(serializer, options = {}) ⇒ Base
Returns a new instance of Base.
47 48 49 50 |
# File 'lib/active_model_serializers/adapter/base.rb', line 47 def initialize(serializer, = {}) @serializer = serializer @instance_options = end |
Instance Attribute Details
#instance_options ⇒ Object (readonly)
Returns the value of attribute instance_options.
45 46 47 |
# File 'lib/active_model_serializers/adapter/base.rb', line 45 def @instance_options end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
45 46 47 |
# File 'lib/active_model_serializers/adapter/base.rb', line 45 def serializer @serializer end |
Class Method Details
.cache_key ⇒ Object
37 38 39 |
# File 'lib/active_model_serializers/adapter/base.rb', line 37 def self.cache_key @cache_key ||= ActiveModelSerializers::Adapter.registered_name(self) end |
.default_key_transform ⇒ Symbol
Sets the default transform for the adapter.
14 15 16 |
# File 'lib/active_model_serializers/adapter/base.rb', line 14 def self.default_key_transform :unaltered end |
.fragment_cache(cached_hash, non_cached_hash) ⇒ Object
41 42 43 |
# File 'lib/active_model_serializers/adapter/base.rb', line 41 def self.fragment_cache(cached_hash, non_cached_hash) non_cached_hash.merge cached_hash end |
.inherited(subclass) ⇒ Object
Automatically register adapters when subclassing
7 8 9 |
# File 'lib/active_model_serializers/adapter/base.rb', line 7 def self.inherited(subclass) ActiveModelSerializers::Adapter.register(subclass) end |
.transform(options) ⇒ Symbol
Determines the transform to use in order of precedence:
adapter option, global config, adapter default.
23 24 25 26 |
# File 'lib/active_model_serializers/adapter/base.rb', line 23 def self.transform() return [:key_transform] if && [:key_transform] ActiveModelSerializers.config.key_transform || default_key_transform end |
.transform_key_casing!(value, options) ⇒ Symbol
Transforms the casing of the supplied value.
33 34 35 |
# File 'lib/active_model_serializers/adapter/base.rb', line 33 def self.transform_key_casing!(value, ) CaseTransform.send(transform(), value) end |
Instance Method Details
#as_json(options = nil) ⇒ Object
58 59 60 |
# File 'lib/active_model_serializers/adapter/base.rb', line 58 def as_json( = nil) serializable_hash() end |
#cache_key ⇒ Object
62 63 64 |
# File 'lib/active_model_serializers/adapter/base.rb', line 62 def cache_key self.class.cache_key end |
#fragment_cache(cached_hash, non_cached_hash) ⇒ Object
66 67 68 |
# File 'lib/active_model_serializers/adapter/base.rb', line 66 def fragment_cache(cached_hash, non_cached_hash) self.class.fragment_cache(cached_hash, non_cached_hash) end |
#serializable_hash(_options = nil) ⇒ Object
Subclasses that implement this method must first call
= ()
54 55 56 |
# File 'lib/active_model_serializers/adapter/base.rb', line 54 def serializable_hash( = nil) fail NotImplementedError, 'This is an abstract method. Should be implemented at the concrete adapter.' end |