81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/trailblazer/1.1/operation/worker.rb', line 81
def file_marshaller_representer
@file_marshaller_representer ||= contract_class.schema(include: [Representable::Hash]).apply do |dfn|
dfn.merge!(
getter: lambda { |*| self[dfn.name.to_sym] },
setter: lambda { |fragment, *| self[dfn.name.to_s] = fragment }
)
dfn.merge!(class: Hash) and next if dfn[:form] or dfn[:twin] next unless dfn[:file]
dfn.merge!(
serialize: lambda { |file, *| Trailblazer::Operation::UploadedFile.new(file, tmp_dir: "/tmp/uploads").to_hash },
deserialize: lambda { |object, hash, *| Trailblazer::Operation::UploadedFile.from_hash(hash) },
class: Hash
)
end
end
|