Sha256: a241de92468d7a059f315a06ede954c15c91968c313575e8e3046cc624bf0760

Contents?: true

Size: 736 Bytes

Versions: 67

Compression:

Stored size: 736 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.erb",
                           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

67 entries across 67 versions & 23 rubygems

Version Path
olek-paperclip-2.3.3 generators/paperclip/paperclip_generator.rb
davidray-paperclip-2.3.3 generators/paperclip/paperclip_generator.rb
mbailey-paperclip-2.3.3 generators/paperclip/paperclip_generator.rb
mbailey-paperclip-2.3.2.1 generators/paperclip/paperclip_generator.rb
mbailey-paperclip-2.3.2 generators/paperclip/paperclip_generator.rb
paperclip-2.3.3 generators/paperclip/paperclip_generator.rb
paperclip-2.3.2 generators/paperclip/paperclip_generator.rb