public
Description: This repo is no longer active, please refer to http://github.com/FreerangeFuture/gluttonberg/
Home | Edit | New

AssetLibraryModels

The models required for the asset library are actually pretty straight-forward.

Asset

Since the assets are localized, the asset model really just acts as a meta model, binding the related localized versions of an asset together. It also stores the information shared between the localized assets — type, categories etc.


class Asset
  include DataMapper::Resource

  property :id, Serial
  property :type, Enum[:image, :video, :document, :archive, :binary]
  property :mime_type, String

  has n, :localizations
  has n, :collections, :through => Resource
end

Localization

This is the actual asset itself. It has a name and a description for the specified dialect/locale and a reference to the actual asset stored on disk. That may work something like dm-paperclip, except it doesn’t assume we only have images.


class Localization
  include DataMapper::Resource

  property :id, Serial
  property :name, String
  property :description, Text

  belongs_to :asset
end

Collection

Collections are just an arbitrary way of organising assets. An asset may belong to multiple collections. The reasoning here is that strict categories or filing systems are inflexible; a user may wish to put a photograph in the press releases and product shot categories.


class Collection
  include DataMapper::Resource

  property :id, Serial
  property :name, String

  has n, :assets, :through => Resource
end

Attachment Mixin

In simple cases, models that need to use assets can have a direct belongs_to association. However, for any situation where custom attributes need to be specified — say an image size — a join model may be used. This join model includes an attachment mixin.

Last edited by lukesutton, Mon Sep 29 18:54:36 -0700 2008
Home | Edit | New
Versions: