Class: Spree::MetafieldDefinition
- Inherits:
-
Object
- Object
- Spree::MetafieldDefinition
- Includes:
- DisplayOn
- Defined in:
- app/models/spree/metafield_definition.rb
Constant Summary collapse
- DISPLAY =
[:both, :back_end]
Class Method Summary collapse
-
.available_resources ⇒ Array<Class>
Returns the available resources.
-
.available_types ⇒ Array<Class>
Returns the available types.
Instance Method Summary collapse
-
#csv_header_name ⇒ String
Returns the CSV header name for this metafield.
-
#field_type ⇒ Object
API-facing token for the STI subclass name stored in ‘metafield_type`.
- #field_type=(value) ⇒ Object
-
#full_key ⇒ String
Returns the full key with namespace.
Class Method Details
.available_resources ⇒ Array<Class>
Returns the available resources
100 101 102 |
# File 'app/models/spree/metafield_definition.rb', line 100 def self.available_resources Spree..enabled_resources end |
.available_types ⇒ Array<Class>
Returns the available types
94 95 96 |
# File 'app/models/spree/metafield_definition.rb', line 94 def self.available_types Spree..types end |
Instance Method Details
#csv_header_name ⇒ String
Returns the CSV header name for this metafield
88 89 90 |
# File 'app/models/spree/metafield_definition.rb', line 88 def csv_header_name "metafield.#{full_key}" end |
#field_type ⇒ Object
API-facing token for the STI subclass name stored in ‘metafield_type`. Reader returns the registered token (`short_text`); writer accepts either the token or the legacy class-name form for back-compat.
64 65 66 |
# File 'app/models/spree/metafield_definition.rb', line 64 def field_type Spree::Metafield::TYPE_CLASS_TO_TOKEN[] || end |
#field_type=(value) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/spree/metafield_definition.rb', line 68 def field_type=(value) v = value.to_s mapped = Spree::Metafield::TYPE_TOKENS[v] # An input is "recognized" when it's either a known token (mapped to a # class) or already a known class name. Anything else gets surfaced as # an error on `field_type` so API clients get a token-vocabulary # message instead of the raw class-name inclusion error on # `metafield_type`. @field_type_input_recognized = !mapped.nil? || Spree::Metafield::TYPE_CLASS_TO_TOKEN.key?(v) self. = mapped || value end |
#full_key ⇒ String
Returns the full key with namespace
82 83 84 |
# File 'app/models/spree/metafield_definition.rb', line 82 def full_key "#{namespace}.#{key}" end |