lib/attached.rb in attached-0.3.3 vs lib/attached.rb in attached-0.3.4

- old
+ new

@@ -152,18 +152,21 @@ # # * :in - allowed values for attached # # Usage: # + # validates_attached_extension :avatar, :is => 'png' # validates_attached_extension :avatar, :in => %w(png jpg) # validates_attached_extension :avatar, :in => [:png, :jpg] # validates_attached_extension :avatar, :in => %w(png jpg), :message => "extension must be :in" # validates_attached_extension :avatar, :in => %w(png jpg), :message => "extension must be :in" def validates_attached_extension(name, options = {}) message = options[:message] message ||= "extension is invalid" + + options[:in] ||= [options[:is]] if options[:is] range = options[:in].map { |element| ".#{element}" } validates_inclusion_of :"#{name}_extension", :in => range, :message => message, :if => options[:if], :unless => options[:unless] \ No newline at end of file