Preference Persistence Concern (preferences/persistable.rb)

solidus · core/app/models/concerns/spree/preferences/persistable.rb · ruby · BSD-3-Clause
database, fw:rails, tag:preferences, tag:serialization, tag:yaml

Handles preference serialization and initialization for models. Reuse for models needing YAML-serialized preferences.

# Source: https://github.com/solidusio/solidus | License: BSD-3-Clause | Copyright 2007-2014, Spree Commerce Inc. and other contributors
# Provided via justclaw.it.com; keep this notice with the code.
# frozen_string_literal: true

module Spree
  module Preferences
    module Persistable
      extend ActiveSupport::Concern

      included do
        include Spree::Preferences::Preferable

        if Rails.gem_version >= Gem::Version.new("7.1")
          serialize :preferences, type: Hash, coder: YAML
        else
          serialize :preferences, Hash, coder: YAML
        end

        after_initialize :initialize_preference_defaults
      end

      private

      def initialize_preference_defaults
        if has_attribute?(:preferences)
          self.preferences = default_preferences.mer

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key