Class: EPlat::Mapping::VirtualCollection::Shopify::Product::Variant::OptionValue
- Inherits:
-
VirtualCollection::Base
- Object
- VirtualCollection::Base
- EPlat::Mapping::VirtualCollection::Shopify::Product::Variant::OptionValue
- Defined in:
- lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource:, map_from:) ⇒ OptionValue
constructor
A new instance of OptionValue.
- #native_attribute_aliases(i) ⇒ Object
Constructor Details
#initialize(resource:, map_from:) ⇒ OptionValue
Returns a new instance of OptionValue.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb', line 11 def initialize(resource:, map_from:) @resource = resource super return unless @resource.try :selected_options @resource.option_values = @resource..map.with_index do |data, i| item = EPlat::Product::Variant::OptionValue.new(variant_id: @resource.id) item.mapping.virtual_collection = self item.add_aliases!(native_attribute_aliases(i), EPlat::Product::Variant::OptionValue.schema) item end end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
9 10 11 |
# File 'lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb', line 9 def resource @resource end |
Instance Method Details
#native_attribute_aliases(i) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/e_plat/mapping/virtual_collection/shopify/product/variant/option_value.rb', line 27 def native_attribute_aliases(i) [ { alias_attribute: { native_key: "[selected_options][#{i}][option_value][id]", e_plat_key: "id", virtual_collection: true, custom_e_plat_getter: '-> { _1&.split("/")&.last }', custom_native_setter: '-> { "gid://shopify/ProductOptionValue/#{_1}" }' } }, { alias_attribute: { native_key: "[selected_options][#{i}][name]", e_plat_key: "name", virtual_collection: true } }, { alias_attribute: { native_key: "[selected_options][#{i}][value]", e_plat_key: "value", virtual_collection: true } } ] end |