Class: ApiSerializer::Schema
- Inherits:
-
Object
- Object
- ApiSerializer::Schema
- Defined in:
- lib/api_serializer/schema.rb
Class Attribute Summary collapse
-
.schema_variants_store ⇒ Object
readonly
Returns the value of attribute schema_variants_store.
Class Method Summary collapse
- .base_template(name, inherits: nil) ⇒ Object
- .deserializer(variant_name = nil, inherits: nil, composes: nil) ⇒ Object
- .deserializer_for(variant_name) ⇒ Object
- .deserializer_template(name, inherits: nil, composes: nil) ⇒ Object
- .fetch_variant(type, abstract, variant_name) ⇒ Object
- .inherited(subclass) ⇒ Object
-
.serializer(variant_name = nil, inherits: nil, composes: nil) ⇒ Object
Called without a variant name, returns a VariantResolver — use this at require time when referring to another schema whose variants may not have been defined yet.
- .serializer_for(variant_name) ⇒ Object
- .serializer_template(name, inherits: nil, composes: nil) ⇒ Object
- .variant?(variant_name, type: :serializer) ⇒ Boolean
Class Attribute Details
.schema_variants_store ⇒ Object (readonly)
Returns the value of attribute schema_variants_store.
9 10 11 |
# File 'lib/api_serializer/schema.rb', line 9 def schema_variants_store @schema_variants_store end |
Class Method Details
.base_template(name, inherits: nil) ⇒ Object
11 12 13 |
# File 'lib/api_serializer/schema.rb', line 11 def base_template(name, inherits: nil, &) define_variant(name, abstract: true, type: :base, inherits:, composes: nil, &) end |
.deserializer(variant_name = nil, inherits: nil, composes: nil) ⇒ Object
30 31 32 |
# File 'lib/api_serializer/schema.rb', line 30 def deserializer(variant_name = nil, inherits: nil, composes: nil, &) define_variant_or_build_resolver(:deserializer, variant_name, inherits: inherits, composes: composes, &) end |
.deserializer_for(variant_name) ⇒ Object
38 39 40 |
# File 'lib/api_serializer/schema.rb', line 38 def deserializer_for(variant_name) deserializer.resolve_transformer(variant_name) end |
.deserializer_template(name, inherits: nil, composes: nil) ⇒ Object
19 20 21 |
# File 'lib/api_serializer/schema.rb', line 19 def deserializer_template(name, inherits: nil, composes: nil, &) define_variant(name, abstract: true, type: :deserializer, inherits:, composes:, &) end |
.fetch_variant(type, abstract, variant_name) ⇒ Object
46 47 48 |
# File 'lib/api_serializer/schema.rb', line 46 def fetch_variant(type, abstract, variant_name) @schema_variants_store&.fetch(type, variant_name, abstract:) end |
.inherited(subclass) ⇒ Object
4 5 6 7 |
# File 'lib/api_serializer/schema.rb', line 4 def inherited(subclass) subclass.instance_variable_set(:@schema_variants_store, @schema_variants_store.clone) if @schema_variants_store super end |
.serializer(variant_name = nil, inherits: nil, composes: nil) ⇒ Object
Called without a variant name, returns a VariantResolver — use this at require time when referring to another schema whose variants may not have been defined yet.
26 27 28 |
# File 'lib/api_serializer/schema.rb', line 26 def serializer(variant_name = nil, inherits: nil, composes: nil, &) define_variant_or_build_resolver(:serializer, variant_name, inherits: inherits, composes: composes, &) end |
.serializer_for(variant_name) ⇒ Object
34 35 36 |
# File 'lib/api_serializer/schema.rb', line 34 def serializer_for(variant_name) serializer.resolve_transformer(variant_name) end |
.serializer_template(name, inherits: nil, composes: nil) ⇒ Object
15 16 17 |
# File 'lib/api_serializer/schema.rb', line 15 def serializer_template(name, inherits: nil, composes: nil, &) define_variant(name, abstract: true, type: :serializer, inherits:, composes:, &) end |
.variant?(variant_name, type: :serializer) ⇒ Boolean
42 43 44 |
# File 'lib/api_serializer/schema.rb', line 42 def variant?(variant_name, type: :serializer) !!fetch_variant(type, false, variant_name.to_sym) end |