Module: ProductTaxonomy::Serializers::Attribute::Data::DataSerializer
- Defined in:
- lib/product_taxonomy/models/serializers/attribute/data/data_serializer.rb
Class Method Summary collapse
Class Method Details
.serialize(attribute) ⇒ Hash
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/product_taxonomy/models/serializers/attribute/data/data_serializer.rb', line 22 def serialize(attribute) if attribute.extended? { "name" => attribute.name, "handle" => attribute.handle, "description" => attribute.description, "friendly_id" => attribute.friendly_id, "values_from" => attribute.values_from.friendly_id, } else { "id" => attribute.id, "name" => attribute.name, "description" => attribute.description, "friendly_id" => attribute.friendly_id, "handle" => attribute.handle, "sorting" => attribute.manually_sorted? ? "custom" : nil, "values" => attribute.sorted_values.map(&:friendly_id), }.compact end end |
.serialize_all ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/product_taxonomy/models/serializers/attribute/data/data_serializer.rb', line 9 def serialize_all # Base attributes are sorted by ID, extended attributes are sorted by the order they were added extended_attributes, base_attributes = ProductTaxonomy::Attribute.all.partition(&:extended?) base_attributes.sort_by!(&:id) { "base_attributes" => base_attributes.map { serialize(_1) }, "extended_attributes" => extended_attributes.map { serialize(_1) }, } end |