Class: Spree::MetafieldDefinition

Inherits:
Object
  • Object
show all
Includes:
DisplayOn
Defined in:
app/models/spree/metafield_definition.rb

Constant Summary collapse

DISPLAY =
[:both, :back_end]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_resourcesArray<Class>

Returns the available resources

Returns:

  • (Array<Class>)


100
101
102
# File 'app/models/spree/metafield_definition.rb', line 100

def self.available_resources
  Spree.metafields.enabled_resources
end

.available_typesArray<Class>

Returns the available types

Returns:

  • (Array<Class>)


94
95
96
# File 'app/models/spree/metafield_definition.rb', line 94

def self.available_types
  Spree.metafields.types
end

Instance Method Details

#csv_header_nameString

Returns the CSV header name for this metafield

Returns:

  • (String)

    eg. metafield.custom.id



88
89
90
# File 'app/models/spree/metafield_definition.rb', line 88

def csv_header_name
  "metafield.#{full_key}"
end

#field_typeObject

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[metafield_type] || metafield_type
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.metafield_type = mapped || value
end

#full_keyString

Returns the full key with namespace

Returns:

  • (String)

    eg. custom.id



82
83
84
# File 'app/models/spree/metafield_definition.rb', line 82

def full_key
  "#{namespace}.#{key}"
end