Class: FriendshipGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_numberObject



7
8
9
10
# File 'lib/generators/friendship/friendship_generator.rb', line 7

def self.next_migration_number
  now = DateTime.now
  "#{now.year}#{'%02d' % now.month}#{'%02d' % now.day}#{'%02d' % now.hour}#{'%02d' % now.minute}#{'%02d' % now.second}"
end

.source_rootObject



12
13
14
# File 'lib/generators/friendship/friendship_generator.rb', line 12

def self.source_root
  @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
end

Instance Method Details

#create_friendship_model_filesObject



17
18
19
20
# File 'lib/generators/friendship/friendship_generator.rb', line 17

def create_friendship_model_files
  template 'friendship.rb', 'app/models/friendship.rb'
  template 'create_friendships.rb', "db/migrate/#{self.class.next_migration_number}_create_friendships.rb"
end