Skip to content

Instantly share code, notes, and snippets.

@yannick
Created March 1, 2010 22:19
Show Gist options
  • Save yannick/318877 to your computer and use it in GitHub Desktop.
Save yannick/318877 to your computer and use it in GitHub Desktop.
class Code < Ohm::Model
include Comparable
attribute :sha1
attribute :md5
attribute :filesize
attribute :mimetype
set :filenames
counter :votes
index :sha1
def filename=(filename)
@filename = filename
end
def filename
@filename
end
def create
return unless valid?
initialize_id
#TODO: hack to put a new filename into the set
filenames << @filename
mutex do
create_model_membership
write
add_to_indices
end
end
private
def initialize_id
self.id = self.sha1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment