Class: SocializationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/socialization/socialization_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object


11
12
13
14
15
16
17
# File 'lib/generators/socialization/socialization_generator.rb', line 11

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#create_migration_fileObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/socialization/socialization_generator.rb', line 19

def create_migration_file
  options[:store].downcase!
  unless STORES.include?(options[:store])
    puts "Invalid store '#{options[:store]}'. The following stores are valid: #{STORES.join(', ')}."
    exit 1
  end

  copy_file "#{options[:store]}/model_follow.rb",  'app/models/follow.rb'
  copy_file "#{options[:store]}/model_like.rb",    'app/models/like.rb'
  copy_file "#{options[:store]}/model_mention.rb", 'app/models/mention.rb'

  if options[:store] == 'active_record'
    migration_template "#{options[:store]}/migration_follows.rb",  'db/migrate/create_follows.rb'
    sleep 1 # wait a second to have a unique migration timestamp
    migration_template "#{options[:store]}/migration_likes.rb",    'db/migrate/create_likes.rb'
    sleep 1 # wait a second to have a unique migration timestamp
    migration_template "#{options[:store]}/migration_mentions.rb", 'db/migrate/create_mentions.rb'
  end
end