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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/wings/attribute_transformer.rb', line 52

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
  attributes[:file_identifier] = obj.id if obj.id.present?
  attributes[:type] = obj..type.to_a
  attributes[:size] = obj.size
  attributes
end