Class: ProductTaxonomy::Serializers::Attribute::Dist::JsonSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/product_taxonomy/models/serializers/attribute/dist/json_serializer.rb

Class Method Summary collapse

Class Method Details

.serialize(attribute, locale: "en") ⇒ Hash

Parameters:

  • attribute (Attribute)
  • locale (String) (defaults to: "en")

    The locale to use for localized attributes.

Returns:

  • (Hash)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/product_taxonomy/models/serializers/attribute/dist/json_serializer.rb', line 19

def serialize(attribute, locale: "en")
  {
    "id" => attribute.gid,
    "name" => attribute.name(locale:),
    "handle" => attribute.handle,
    "description" => attribute.description(locale:),
    "extended_attributes" => attribute.extended_attributes.sort_by(&:name).map do |ext_attr|
      {
        "name" => ext_attr.name(locale:),
        "handle" => ext_attr.handle,
      }
    end,
    "values" => attribute.sorted_values(locale:).map do |value|
      Serializers::Value::Dist::JsonSerializer.serialize(value, locale:)
    end,
  }
end

.serialize_all(version:, locale: "en") ⇒ Object



9
10
11
12
13
14
# File 'lib/product_taxonomy/models/serializers/attribute/dist/json_serializer.rb', line 9

def serialize_all(version:, locale: "en")
  {
    "version" => version,
    "attributes" => ProductTaxonomy::Attribute.sorted_base_attributes.map { serialize(_1, locale:) },
  }
end