Class: S3CorsFileupload::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/s3_cors_fileupload/install/install_generator.rb

Constant Summary collapse

VALID_TEMPLATE_LANGS =
[:erb, :haml]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



52
53
54
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 52

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

Instance Method Details

#create_config_fileObject



19
20
21
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 19

def create_config_file
  copy_file 'amazon_s3.yml', 'config/amazon_s3.yml'
end

#create_controllerObject



31
32
33
34
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 31

def create_controller
  copy_file 's3_uploads_controller.rb', 'app/controllers/s3_uploads_controller.rb'
  copy_file 's3_uploads.js', 'app/assets/javascripts/s3_uploads.js'
end

#create_migration_fileObject



23
24
25
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 23

def create_migration_file
  migration_template 'create_source_files.rb', 'db/migrate/create_source_files.rb' if options.migration?
end

#create_model_fileObject



27
28
29
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 27

def create_model_file
  copy_file 'source_file.rb', 'app/models/source_file.rb'
end

#create_viewsObject



36
37
38
39
40
41
42
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 36

def create_views
  template_language = options.template_language if VALID_TEMPLATE_LANGS.include?(options.template_language.to_sym)
  template_language ||= 'erb'
  Dir.foreach(File.expand_path("../templates/views/#{template_language}", __FILE__)).reject { |file_name| %w(. ..).include?(file_name) }.each do |file_name|
    copy_file "views/#{template_language}/#{file_name}", "app/views/s3_uploads/#{file_name}"
  end
end

#setup_routesObject



44
45
46
47
48
49
50
# File 'lib/generators/s3_cors_fileupload/install/install_generator.rb', line 44

def setup_routes
  route(
    ["resources :source_files, :only => [:index, :create, :destroy], :controller => 's3_uploads' do", "\n",
  "    get :generate_key, :on => :collection", "\n",
  "  end"].join
  )
end