Module: ProductTaxonomy::Serializers::Value::Docs::ReversedSerializer

Defined in:
lib/product_taxonomy/models/serializers/value/docs/reversed_serializer.rb

Class Method Summary collapse

Class Method Details

.serialize(value) ⇒ Hash

Returns The serialized value. Categories aren't embedded — users navigate to the parent attribute page to see them, since duplicating the category list across every value of an attribute would explode the YAML by orders of magnitude.

Parameters:

  • value (Value)

    The value to serialize.

Returns:

  • (Hash)

    The serialized value. Categories aren't embedded — users navigate to the parent attribute page to see them, since duplicating the category list across every value of an attribute would explode the YAML by orders of magnitude.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/product_taxonomy/models/serializers/value/docs/reversed_serializer.rb', line 19

def serialize(value)
  attribute = value.primary_attribute
  {
    "id" => value.gid,
    "handle" => value.handle,
    "name" => value.name,
    "friendly_id" => value.friendly_id,
    "attribute" => attribute && {
      "handle" => attribute.handle,
      "name" => attribute.name,
    },
  }
end

.serialize_allObject



9
10
11
12
13
# File 'lib/product_taxonomy/models/serializers/value/docs/reversed_serializer.rb', line 9

def serialize_all
  {
    "values" => ProductTaxonomy::Value.all_values_sorted.map { |value| serialize(value) },
  }
end