Class: Spree::MetafieldDefinition
- Inherits:
-
Object
- Object
- Spree::MetafieldDefinition
- Includes:
- DisplayOn, SearchCapabilities
- Defined in:
- app/models/spree/metafield_definition.rb,
app/models/spree/metafield_definition/search_capabilities.rb
Defined Under Namespace
Modules: SearchCapabilities
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.
Methods included from SearchCapabilities
Class Method Details
.available_resources ⇒ Array<Class>
Returns the available resources
101 102 103 |
# File 'app/models/spree/metafield_definition.rb', line 101 def self.available_resources Spree..enabled_resources end |
.available_types ⇒ Array<Class>
Returns the available types
95 96 97 |
# File 'app/models/spree/metafield_definition.rb', line 95 def self.available_types Spree..types end |
Instance Method Details
#csv_header_name ⇒ String
Returns the CSV header name for this metafield
89 90 91 |
# File 'app/models/spree/metafield_definition.rb', line 89 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.
65 66 67 |
# File 'app/models/spree/metafield_definition.rb', line 65 def field_type Spree::Metafield::TYPE_CLASS_TO_TOKEN[] || end |
#field_type=(value) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/spree/metafield_definition.rb', line 69 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
83 84 85 |
# File 'app/models/spree/metafield_definition.rb', line 83 def full_key "#{namespace}.#{key}" end |