Module: Spree::PreferenceSchema

Extended by:
ActiveSupport::Concern
Included in:
Base, CommissionRule, DeliveryMethodRule, Integration, SellerRequirement
Defined in:
app/models/concerns/spree/preference_schema.rb,
app/models/concerns/spree/preference_schema/json_schema.rb

Overview

Adds class-level helpers that surface a JSON-friendly description of a Preferable class's preference :name, :type, default: declarations.

Used by the admin API (/payment_methods/types, /promotion_actions/types, /promotion_rules/types) so that admin UIs can render configuration forms for any provider/action/rule subclass without hard-coding field lists.

Also hosts the subclass registry (registers_subclasses_via) that find_by_api_type and subclasses_with_preference_schema resolve against. That is a lodger rather than a natural fit — the registry is its own concept, and Spree::CalculatedAdjustments resolves an equivalent one separately. Extract a Spree::RegisteredSubclasses concern when a family needs the registry without preferences.

Defined Under Namespace

Modules: JsonSchema Classes: UndeclaredRegistryError

Instance Method Summary collapse

Instance Method Details

#serialized_preferences ⇒ Hash{String => Object}

Wire-safe view of preferences with :password-typed values masked. Lives here (not in the serializer) so any consumer holding a Preferable instance gets the same safety guarantee — secrets must never leave the server in plaintext. Keys are stringified to match the wire shape expected by JSON clients.

Returns:

  • (Hash{String => Object})


39
40
41
# File 'app/models/concerns/spree/preference_schema.rb', line 39

def serialized_preferences
  Spree::Preferences::Masking.serialize(self)
end