Sha256: 4f5e522099bdc87696c3248dcb6091273f276382d95747318f0ed2f222d0fec6

Contents?: true

Size: 744 Bytes

Versions: 5

Compression:

Stored size: 744 Bytes

Contents

class PaperclipGenerator < Rails::Generator::NamedBase
  attr_accessor :attachments, :migration_name
 
  def initialize(args, options = {})
    super
    @class_name, @attachments = args[0], args[1..-1]
  end
 
  def manifest    
    file_name = generate_file_name
    @migration_name = file_name.camelize
    record do |m|
      m.migration_template "paperclip_migration.rb",
                           File.join('db', 'migrate'),
                           :migration_file_name => file_name
    end
  end 
  
  private 
  
  def generate_file_name
    names = attachments.map{|a| a.underscore }
    names = names[0..-2] + ["and", names[-1]] if names.length > 1
    "add_attachments_#{names.join("_")}_to_#{@class_name.underscore}"
  end
 
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
jcnetdev-paperclip-1.0.20080704 generators/paperclip/paperclip_generator.rb
jcnetdev-paperclip-1.1 generators/paperclip/paperclip_generator.rb
avatar-0.0.5 test/lib/paperclip/generators/paperclip/paperclip_generator.rb
paperclip-2.1.0 generators/paperclip/paperclip_generator.rb
paperclip-2.1.2 generators/paperclip/paperclip_generator.rb