Class: ProductTaxonomy::ExtendedAttribute

Inherits:
Attribute
  • Object
show all
Defined in:
lib/product_taxonomy/models/extended_attribute.rb

Constant Summary

Constants included from Indexed

Indexed::NotFoundError

Instance Attribute Summary collapse

Attributes inherited from Attribute

#extended_attributes, #friendly_id, #handle, #id, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Attribute

#add_extended_attribute, #add_value, #extended?, #gid, load_from_source, #manually_sorted?, next_id, reset, sorted_base_attributes, #sorted_values

Methods included from Localized

#localizations, #validate_localizations!

Methods included from Indexed

#add, #all, #create_validate_and_add!, #duplicate?, extended, #find_by, #find_by!, #hashed_by, #hashed_models, #size

Methods included from FormattedValidationErrors

#validate!

Constructor Details

#initialize(name:, handle:, description:, friendly_id:, values_from:) ⇒ ExtendedAttribute

Returns a new instance of ExtendedAttribute.

Parameters:

  • name (String)

    The name of the attribute.

  • handle (String)

    The handle of the attribute.

  • description (String)

    The description of the attribute.

  • friendly_id (String)

    The friendly ID of the attribute.

  • values_from (Attribute, String)

    A resolved Attribute object. When resolving fails, pass the friendly ID instead.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/product_taxonomy/models/extended_attribute.rb', line 23

def initialize(name:, handle:, description:, friendly_id:, values_from:)
  @values_from = values_from
  values_from.add_extended_attribute(self) if values_from.is_a?(Attribute)
  super(
    id: values_from.try(:id),
    name:,
    handle:,
    description:,
    friendly_id:,
    values: values_from.try(:values),
    is_manually_sorted: values_from.try(:manually_sorted?) || false,
  )
end

Instance Attribute Details

#values_fromObject (readonly) Also known as: base_attribute

Returns the value of attribute values_from.



13
14
15
# File 'lib/product_taxonomy/models/extended_attribute.rb', line 13

def values_from
  @values_from
end

Class Method Details

.localizationsObject



6
7
8
# File 'lib/product_taxonomy/models/extended_attribute.rb', line 6

def localizations
  superclass.localizations # Extended attribute localizations are defined in the same place as attributes
end