Skip to content

Commit

Permalink
Implement :required option.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyaka committed Apr 8, 2010
1 parent c2f2389 commit 4393e95
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/joint.rb
Expand Up @@ -11,7 +11,10 @@ def self.configure(model)
end

module ClassMethods
def attachment(name)
def attachment(name, options = {})
options.symbolize_keys!
name = name.to_sym

self.attachment_names << name

after_save :save_attachments
Expand All @@ -23,6 +26,8 @@ def attachment(name)
key "#{name}_size".to_sym, Integer
key "#{name}_type".to_sym, String

validates_presence_of(name) if options[:required]

class_eval <<-EOC
def #{name}
@#{name} ||= AttachmentProxy.new(self, :#{name})
Expand Down
3 changes: 1 addition & 2 deletions test/test_joint.rb
Expand Up @@ -306,8 +306,7 @@ def @image.original_filename
@model_class = Class.new do
include MongoMapper::Document
plugin Joint
attachment :file
validates_presence_of :file
attachment :file, :required => true
end
end

Expand Down

0 comments on commit 4393e95

Please sign in to comment.