Sha256: 6ed60e2b053e6c9bd24f3ffb80d47d856315e880f667384a09ef0040c8709f1e

Contents?: true

Size: 704 Bytes

Versions: 2

Compression:

Stored size: 704 Bytes

Contents

class TagFieldType < FieldType
  attr_accessor :tag_list

  validates :tag_list, presence: true, if: :validate_presence?

  def elasticsearch_mapping
    { name: mapping_field_name, analyzer: :keyword }
  end

  def data=(data_hash)
    @tag_list = tag_list_to_a data_hash['tag_list']
  end

  def field_item_as_indexed_json_for_field_type(field_item, options = {})
    json = {}
    json[mapping_field_name] = tag_list_to_a field_item.data['tag_list']
    json
  end

  private

  def mapping_field_name
    "#{field_name.parameterize(separator: '_')}_tags"
  end

  def validate_presence?
    validations.key? :presence
  end

  def tag_list_to_a(string)
    string&.split(',')&.map(&:strip)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cortex-plugins-core-2.1.1 app/models/tag_field_type.rb
cortex-plugins-core-2.1.0 app/models/tag_field_type.rb