Sha256: 5ee928d84ac8466e14530089e50d047ff104d79cba299843751de85469ef917c
Contents?: true
Size: 910 Bytes
Versions: 4
Compression:
Stored size: 910 Bytes
Contents
class AuthorFieldType < FieldType attr_accessor :author_name jsonb_accessor :data, author_name: :string validates :author_name, presence: true, if: :validate_presence? def data=(data_hash) data_hash[:author_name] = data_hash[:default_author_name] if data_hash.deep_symbolize_keys[:author_name].blank? @author_name = data_hash.deep_symbolize_keys[:author_name] end def field_item_as_indexed_json_for_field_type(field_item, options = {}) json = {} json[mapping_field_name] = field_item.data['author_name'] json end def mapping { name: mapping_field_name, type: :string, analyzer: :snowball } end private def mapping_field_name "#{field_name.parameterize(separator: '_')}_author" end def author_name_present errors.add(:author_name, 'must be present') if @author_name.empty? end def validate_presence? validations.key? :presence end end
Version data entries
4 entries across 4 versions & 1 rubygems