gzigzigzeo / carrierwave-meta

File's metadata saving plugin for carrierwave
MIT License
85 stars 48 forks source link

Can it only save the meta in one single column just like paperclip-meta #3

Closed newlix closed 11 years ago

newlix commented 12 years ago

Hi, Can carrierwave-meta support save the meta to single text column? It will be much easier to maintain the db schema when we have to add new versions. Thank you.

https://github.com/y8/paperclip-meta

newlix commented 12 years ago

Hi, I found your post on google groups. This was what i thought. http://groups.google.com/group/carrierwave/browse_thread/thread/54401352ddf42a4e/ceeadb8c2c463073?lnk=gst&q=width#ceeadb8c2c463073

I am wondering what's the problem with the design?

gzigzigzeo commented 12 years ago

I think that value storage is not the task of this plugin. Uploader's model could be ActiveRecord instance, regular object or nil. The only plugin obligation is to retrieve metadata and notify model (if it's not nil) that metadata is changed.

Another reason why I abandoned single field is that I got problems with base64 column. In particular cases it requires about 2048 bytes length, it should be non-utf8 encoding (mysql fails to create long UTF8 string fields - custom migration needed), it should be fallback function for blank/non-decodable value, there is no way to determine necessary length of this field and so on.

I think, the right way is to implement custom base64 field bucket serializer for ActiveRecord in separate gem.

But because of this: https://github.com/y8/paperclip-meta/pull/1 I think that your feature request should be implemented. I'll think about architecture in few days and I'll try to reimplement it here.

alxgsv commented 11 years ago

Main reason for storing in one serialized field — no migrations after adding new version.

Why base64? Serialization in AR done by YAML. No problems with utf-8.

pdf commented 11 years ago

Yeah, this is a deal-breaker for me.

gzigzigzeo commented 11 years ago

I think, the most logical way to implement this behaviour is to use composed_of with OpenStruct. I did not tested it yet but I think it should work:

serialize ImageMeta, OpenStruct composed_of :image_meta, class_name: 'OpenStruct', mapping: [ %w(image_width width), %w(image_height height), %w(image_big_width big_width), %w(image_big_height big_height) ]

The only thing I could implement in this gem is a shortcut method which will return real mapping I'll try to make a spec for such case.

gzigzigzeo commented 11 years ago

Done, see new readme.