Class: AssetFieldType

Inherits:
FieldType
  • Object
show all
Defined in:
app/models/asset_field_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assetObject (readonly)

Returns the value of attribute asset.



4
5
6
# File 'app/models/asset_field_type.rb', line 4

def asset
  @asset
end

#asset_dataObject

Returns the value of attribute asset_data.



5
6
7
# File 'app/models/asset_field_type.rb', line 5

def asset_data
  @asset_data
end

Instance Method Details

#dataObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/asset_field_type.rb', line 17

def data
  return {} if errors.any? || attacher.errors.any?
  {
    asset: {
      original_filename: @original_filename,
      # TODO: updated_at: asset.updated_at, -- Does Shrine give this to us? Potentially distinct from record's updated_at
      versions: versions_data
    },
    shrine_asset: asset.to_json
  }
end

#data=(data_hash) ⇒ Object



12
13
14
15
# File 'app/models/asset_field_type.rb', line 12

def data=(data_hash)
  assign data_hash['asset'] if data_hash['asset']
  @asset = attacher.get
end

#field_item_as_indexed_json_for_field_type(field_item, options = {}) ⇒ Object



29
30
31
32
33
# File 'app/models/asset_field_type.rb', line 29

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

#mappingObject



35
36
37
# File 'app/models/asset_field_type.rb', line 35

def mapping
  { name: mapping_field_name, type: :string, analyzer: :keyword }
end