class Para::Stall::Inputs::VariantsMatrixInput

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/para/stall/inputs/variants_matrix_input.rb, line 7
def initialize(*)
  super
  options[:label] = false
end

Public Instance Methods

input(wrapper_options = nil) click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 12
def input(wrapper_options = nil)
  ensure_target_relation_present!

  ensure_empty_variant_if_needed

  template.render partial: 'para/stall/inputs/variants_matrix', locals: {
    form: @builder,
    model: model,
    attribute_name: attribute_name,
    all_properties: all_properties,
    properties: properties,
    variants: variants,
    dom_identifier: dom_identifier,
    variant_row_locals: variant_row_locals,
    allow_empty_variant: allow_empty_variant
  }
end

Private Instance Methods

all_properties() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 32
def all_properties
  @all_properties ||= Property.includes(:property_values).all.map do |property|
    VariantsPropertyConfig.new(resource, property, unsorted_variants)
  end
end
allow_empty_variant() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 68
def allow_empty_variant
  @allow_empty_variant ||= options.fetch(:allow_empty_variant, true)
end
dom_identifier() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 50
def dom_identifier
  @dom_identifier ||= [
    model.model_name.element,
    resource.id || resource.object_id,
    attribute_name
  ].join('-')
end
ensure_empty_variant_if_needed() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 72
def ensure_empty_variant_if_needed
  object.variants.build if object.variants.empty? && allow_empty_variant
end
properties() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 38
def properties
  @properties ||= all_properties.select(&:active?)
end
unsorted_variants() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 42
def unsorted_variants
  @unsorted_variants ||= resource.send(attribute_name)
end
variant_row_locals() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 58
def variant_row_locals
  {
    model: model,
    attribute_name: attribute_name,
    all_properties: all_properties,
    properties: properties,
    dom_identifier: dom_identifier
  }
end
variants() click to toggle source
# File lib/para/stall/inputs/variants_matrix_input.rb, line 46
def variants
  @variants ||= unsorted_variants.sort_by(&method(:variant_sort_method))
end