Class: Mercury::Generators::Install::ImagesGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/mercury/install/images/images_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Implement the required interface for Rails::Generators::Migration.



41
42
43
# File 'lib/generators/mercury/install/images/images_generator.rb', line 41

def self.next_migration_number(dirname) #:nodoc:
  ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#add_gemfile_dependenciesObject



33
34
35
36
37
38
# File 'lib/generators/mercury/install/images/images_generator.rb', line 33

def add_gemfile_dependencies
  append_to_file "Gemfile", %Q{gem 'paperclip'}
  if options[:orm] == 'mongoid'
    append_to_file "Gemfile", %Q{gem 'mongoid-paperclip', :require => 'mongoid_paperclip'}
  end
end

#add_routesObject



27
28
29
30
31
# File 'lib/generators/mercury/install/images/images_generator.rb', line 27

def add_routes
  route %Q{  namespace :mercury do
      resources :images
    end}
end

#copy_controllerObject



23
24
25
# File 'lib/generators/mercury/install/images/images_generator.rb', line 23

def copy_controller
  copy_file 'images_controller.rb', 'app/controllers/mercury/images_controller.rb'
end

#copy_modelsObject



14
15
16
17
18
19
20
21
# File 'lib/generators/mercury/install/images/images_generator.rb', line 14

def copy_models
  if options[:orm] == 'mongoid'
    copy_file 'mongoid_paperclip_image.rb', 'app/models/mercury/image.rb'
  else
    copy_file 'ar_paperclip_image.rb', 'app/models/mercury/image.rb'
    migration_template 'ar_paperclip_image_migration.rb', 'db/migrate/create_mercury_images.rb'
  end
end