Sha256: 9668589ba89dfe362130223c71dc162d34dffe3eb4c5e4ac4b8492c32780da04

Contents?: true

Size: 572 Bytes

Versions: 11

Compression:

Stored size: 572 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

11 entries across 11 versions & 1 rubygems

Version Path
alchemy-solidus-3.3.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.2.2 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.2.1 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.2.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.1.1 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.1.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.0.2 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.0.1 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-3.0.0 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-2.5.1 app/models/alchemy/essence_spree_taxon.rb
alchemy-solidus-2.5.0 app/models/alchemy/essence_spree_taxon.rb