Class: PaperclipGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- PaperclipGenerator
- Defined in:
- lib/generators/paperclip/paperclip_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate_migration ⇒ Object
- #migration_class_name ⇒ Object
- #migration_file_name ⇒ Object
- #migration_name ⇒ Object
- #migration_version ⇒ Object
Class Method Details
.source_root ⇒ Object
11 12 13 |
# File 'lib/generators/paperclip/paperclip_generator.rb', line 11 def self.source_root @source_root ||= File.('../templates', __FILE__) end |
Instance Method Details
#generate_migration ⇒ Object
15 16 17 18 19 |
# File 'lib/generators/paperclip/paperclip_generator.rb', line 15 def generate_migration migration_template("paperclip_migration.rb.erb", "db/migrate/#{migration_file_name}", migration_version: migration_version) end |
#migration_class_name ⇒ Object
29 30 31 |
# File 'lib/generators/paperclip/paperclip_generator.rb', line 29 def migration_class_name migration_name.camelize end |
#migration_file_name ⇒ Object
25 26 27 |
# File 'lib/generators/paperclip/paperclip_generator.rb', line 25 def migration_file_name "#{migration_name}.rb" end |
#migration_name ⇒ Object
21 22 23 |
# File 'lib/generators/paperclip/paperclip_generator.rb', line 21 def migration_name "add_attachment_#{.join("_")}_to_#{name.underscore.pluralize}" end |
#migration_version ⇒ Object
33 34 35 36 37 |
# File 'lib/generators/paperclip/paperclip_generator.rb', line 33 def migration_version if Rails.version.start_with? "5" "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end |