Class: LetsrateGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/letsrate/letsrate_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_rate_path_to_routeObject



27
28
29
# File 'lib/generators/letsrate/letsrate_generator.rb', line 27

def add_rate_path_to_route
  route "post '/rate' => 'rater#create', :as => 'rate'"
end

#copyingObject



9
10
11
12
13
14
15
16
# File 'lib/generators/letsrate/letsrate_generator.rb', line 9

def copying
  copy_file 'jquery.raty.js', 'app/assets/javascripts/jquery.raty.js'
  copy_file 'star-on.png', 'app/assets/images/star-on.png'
  copy_file 'star-off.png', 'app/assets/images/star-off.png'
  copy_file 'star-half.png', 'app/assets/images/star-half.png'
  copy_file 'letsrate.js.erb', 'app/assets/javascripts/letsrate.js.erb'
  copy_file 'rater_controller.rb', 'app/controllers/rater_controller.rb'
end

#create_cacheable_migrationObject



32
33
34
# File 'lib/generators/letsrate/letsrate_generator.rb', line 32

def create_cacheable_migration
  migration_template "cache_migration.rb", "db/migrate/create_rating_caches.rb"
end

#create_migrationObject



37
38
39
# File 'lib/generators/letsrate/letsrate_generator.rb', line 37

def create_migration
  migration_template "migration.rb", "db/migrate/create_rates.rb"
end

#create_modelObject



19
20
21
22
23
24
25
# File 'lib/generators/letsrate/letsrate_generator.rb', line 19

def create_model
  model_file = File.join('app/models', "#{file_path}.rb")
  raise "User model (#{model_file}) must exits." unless File.exists?(model_file)
  class_collisions 'Rate'
  template 'model.rb', File.join('app/models', "rate.rb")
  template 'cache_model.rb', File.join('app/models', "rating_cache.rb")
end