Class: Spree::CustomField
- Inherits:
-
Object
- Object
- Spree::CustomField
- Defined in:
- app/models/spree/custom_field.rb
Direct Known Subclasses
Spree::CustomFields::Boolean, Spree::CustomFields::Json, Spree::CustomFields::LongText, Spree::CustomFields::Number, Spree::CustomFields::RichText, Spree::CustomFields::ShortText
Constant Summary collapse
- TYPE_TOKENS =
Map of API-facing tokens to Ruby STI class names. The wire format is the token (
short_text); the database column stores the class name. Reads translate to the token viafield_type; writes accept either form. Plugin-defined types fall through to the raw class name until a registration API lands. { 'short_text' => 'Spree::CustomFields::ShortText', 'long_text' => 'Spree::CustomFields::LongText', 'rich_text' => 'Spree::CustomFields::RichText', 'number' => 'Spree::CustomFields::Number', 'boolean' => 'Spree::CustomFields::Boolean', 'json' => 'Spree::CustomFields::Json' }.freeze
- TYPE_CLASS_TO_TOKEN =
TYPE_TOKENS.invert.freeze
- FIELD_TYPE_TOKENS =
Array form consumed by serializers via
typelize field_type: Spree::CustomField::FIELD_TYPE_TOKENS. Typelizer emits a string-literal union in TypeScript and{type: string, enum: […]}in OpenAPI (string-array form was added in typelizer 0.10.0). TYPE_TOKENS.keys.freeze
Class Method Summary collapse
-
.searchable? ⇒ Boolean
Whether CustomFieldDefinition may enable
searchable/sortablefor this STI type. - .sortable? ⇒ Boolean
Instance Method Summary collapse
- #csv_value ⇒ Object
-
#field_type ⇒ Object
API-facing form of the STI
typecolumn. -
#metafield_definition ⇒ Object
Deprecated 6.0 names, removed in 6.3.
- #metafield_definition=(value) ⇒ Object
- #metafield_definition_id ⇒ Object
- #metafield_definition_id=(value) ⇒ Object
- #name ⇒ Object
- #serialize_value ⇒ Object
Class Method Details
.searchable? ⇒ Boolean
Whether CustomFieldDefinition may enable searchable / sortable for
this STI type. Used only by definition validations (not by SearchProvider
indexing). Defaults to false; subclasses override (e.g. ShortText).
27 28 29 |
# File 'app/models/spree/custom_field.rb', line 27 def self.searchable? false end |
.sortable? ⇒ Boolean
31 32 33 |
# File 'app/models/spree/custom_field.rb', line 31 def self.sortable? false end |
Instance Method Details
#csv_value ⇒ Object
86 87 88 |
# File 'app/models/spree/custom_field.rb', line 86 def csv_value value.to_s end |
#field_type ⇒ Object
API-facing form of the STI type column. Returns the token
(short_text) when the row's type is a registered built-in; falls
through to the raw class name for plugin types.
self[:type] reads the raw column to bypass AR's STI reader (which
returns the resolved class constant, not a string).
49 50 51 |
# File 'app/models/spree/custom_field.rb', line 49 def field_type TYPE_CLASS_TO_TOKEN[self[:type]] || self[:type] end |
#metafield_definition ⇒ Object
Deprecated 6.0 names, removed in 6.3
93 94 95 96 |
# File 'app/models/spree/custom_field.rb', line 93 def Spree::Deprecation.warn('#metafield_definition is deprecated and will be removed in Spree 6.3. Use #custom_field_definition instead.') custom_field_definition end |
#metafield_definition=(value) ⇒ Object
108 109 110 111 |
# File 'app/models/spree/custom_field.rb', line 108 def (value) Spree::Deprecation.warn('#metafield_definition= is deprecated and will be removed in Spree 6.3. Use #custom_field_definition= instead.') self.custom_field_definition = value end |
#metafield_definition_id ⇒ Object
98 99 100 101 |
# File 'app/models/spree/custom_field.rb', line 98 def Spree::Deprecation.warn('#metafield_definition_id is deprecated and will be removed in Spree 6.3. Use #custom_field_definition_id instead.') custom_field_definition_id end |
#metafield_definition_id=(value) ⇒ Object
103 104 105 106 |
# File 'app/models/spree/custom_field.rb', line 103 def (value) Spree::Deprecation.warn('#metafield_definition_id= is deprecated and will be removed in Spree 6.3. Use #custom_field_definition_id= instead.') self.custom_field_definition_id = value end |
#name ⇒ Object
113 114 115 116 |
# File 'app/models/spree/custom_field.rb', line 113 def name Spree::Deprecation.warn('#name is deprecated and will be removed in Spree 6.3. Use #label instead.') label end |
#serialize_value ⇒ Object
82 83 84 |
# File 'app/models/spree/custom_field.rb', line 82 def serialize_value value end |