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.
49 50 51 52 |
# File 'lib/active_model_serializers/adapter/base.rb', line 49 def initialize(serializer, = {}) @serializer = serializer @instance_options = end |
Instance Attribute Details
#instance_options ⇒ Object (readonly)
Returns the value of attribute instance_options.
47 48 49 |
# File 'lib/active_model_serializers/adapter/base.rb', line 47 def @instance_options end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
47 48 49 |
# File 'lib/active_model_serializers/adapter/base.rb', line 47 def serializer @serializer end |
Class Method Details
.cache_key ⇒ Object
39 40 41 |
# File 'lib/active_model_serializers/adapter/base.rb', line 39 def self.cache_key @cache_key ||= ActiveModelSerializers::Adapter.registered_name(self) end |
.default_key_transform ⇒ Symbol
Sets the default transform for the adapter.
16 17 18 |
# File 'lib/active_model_serializers/adapter/base.rb', line 16 def self.default_key_transform :unaltered end |
.fragment_cache(cached_hash, non_cached_hash) ⇒ Object
43 44 45 |
# File 'lib/active_model_serializers/adapter/base.rb', line 43 def self.fragment_cache(cached_hash, non_cached_hash) non_cached_hash.merge cached_hash end |
.inherited(subclass) ⇒ Object
Automatically register adapters when subclassing
9 10 11 |
# File 'lib/active_model_serializers/adapter/base.rb', line 9 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.
25 26 27 28 |
# File 'lib/active_model_serializers/adapter/base.rb', line 25 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.
35 36 37 |
# File 'lib/active_model_serializers/adapter/base.rb', line 35 def self.transform_key_casing!(value, ) CaseTransform.send(transform(), value) end |
Instance Method Details
#as_json(options = nil) ⇒ Object
60 61 62 |
# File 'lib/active_model_serializers/adapter/base.rb', line 60 def as_json( = nil) serializable_hash() end |
#cache_key ⇒ Object
64 65 66 |
# File 'lib/active_model_serializers/adapter/base.rb', line 64 def cache_key self.class.cache_key end |
#fragment_cache(cached_hash, non_cached_hash) ⇒ Object
68 69 70 |
# File 'lib/active_model_serializers/adapter/base.rb', line 68 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
= ()
56 57 58 |
# File 'lib/active_model_serializers/adapter/base.rb', line 56 def serializable_hash( = nil) fail NotImplementedError, 'This is an abstract method. Should be implemented at the concrete adapter.' end |