Class: Wings::FileAttributeTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/wings/attribute_transformer.rb

Instance Method Summary collapse

Instance Method Details

#run(obj) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wings/attribute_transformer.rb', line 59

def run(obj)
  keys = obj..class.fields

  attributes = keys.each_with_object({}) do |attr_name, mem|
    next unless obj.respond_to?(attr_name) && !mem.key?(attr_name.to_sym)
    mem[attr_name.to_sym] = TransformerValueMapper.for(obj.public_send(attr_name)).result
  end

  attributes[:original_filename] = obj.original_name

  if obj.id.present?
    uri = Hyrax.config.translate_id_to_uri.call(obj.id)
    attributes[:file_identifier] = Wings::Valkyrie::Storage.cast_to_valkyrie_id(uri)
  end
  attributes[:type] = obj..type.to_a
  attributes[:size] = obj.size
  attributes
end