Class: AssetFieldType
- Inherits:
-
FieldType
- Object
- FieldType
- AssetFieldType
- Defined in:
- app/models/asset_field_type.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#asset_data ⇒ Object
Returns the value of attribute asset_data.
Instance Method Summary collapse
- #data ⇒ Object
- #data=(data_hash) ⇒ Object
- #field_item_as_indexed_json_for_field_type(field_item, options = {}) ⇒ Object
- #mapping ⇒ Object
Instance Attribute Details
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
4 5 6 |
# File 'app/models/asset_field_type.rb', line 4 def asset @asset end |
#asset_data ⇒ Object
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
#data ⇒ Object
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, = {}) json = {} json[mapping_field_name] = field_item.data['asset']['original_filename'] json end |
#mapping ⇒ Object
35 36 37 |
# File 'app/models/asset_field_type.rb', line 35 def mapping { name: mapping_field_name, type: :string, analyzer: :keyword } end |