Sha256: bce403491af532287c08db2e083bd521e261b3fa983622582527489883cf27c6

Contents?: true

Size: 588 Bytes

Versions: 5

Compression:

Stored size: 588 Bytes

Contents

# frozen_string_literal: true

module Alchemy
  class EssenceSpreeTaxon < ActiveRecord::Base
    TAXON_ID = /\A\d+\z/

    belongs_to :taxon,
      class_name: "Spree::Taxon",
      optional: true,
      foreign_key: "taxon_id"

    acts_as_essence(ingredient_column: :taxon)

    def ingredient=(taxon_or_id)
      case taxon_or_id
      when TAXON_ID, ""
        self.taxon_id = taxon_or_id
      when Spree::Taxon
        self.taxon = taxon_or_id
      else
        super
      end
    end

    def preview_text(_maxlength)
      return unless taxon
      taxon.name
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alchemy-solidus-5.0.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-4.1.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-4.0.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-4.0.0.pre.b2 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-4.0.0.pre.b1 app/models/alchemy/essence_spree_taxon.rb