Sha256: 3e72dcd7c8a5af6d2e2672b5ce009dd11bf7ee916f3ee3629ea7d3026e79274f

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'spree/core/class_constantizer'
require 'spree/core/nested_class_set'

module Spree
  module Core
    module EnvironmentExtension
      extend ActiveSupport::Concern

      class_methods do
        def add_class_set(name, default: [])
          define_method(name) do
            set = instance_variable_get("@#{name}")
            set ||= send("#{name}=", default)
            set
          end

          define_method("#{name}=") do |klasses|
            set = ClassConstantizer::Set.new
            set.concat(klasses)
            instance_variable_set("@#{name}", set)
          end
        end

        def add_nested_class_set(name, default: {})
          define_method(name) do
            set = instance_variable_get(:"@#{name}")
            set ||= send(:"#{name}=", default)
            set
          end

          define_method(:"#{name}=") do |hash|
            set = Spree::Core::NestedClassSet.new(hash)
            instance_variable_set(:"@#{name}", set)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_core-4.4.2 lib/spree/core/environment_extension.rb
solidus_core-4.4.1 lib/spree/core/environment_extension.rb
solidus_core-4.4.0 lib/spree/core/environment_extension.rb