Class: FriendshipGenerator

Inherits:
Rails::Generators::NamedBase
  • 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_number(path) ⇒ Object



49
50
51
52
# File 'lib/generators/friendship/friendship_generator.rb', line 49

def self.next_migration_number(path)
  require  'rails/generators/active_record'
  ActiveRecord::Generators::Base.next_migration_number path
end

Instance Method Details

#class_nameObject



40
41
42
# File 'lib/generators/friendship/friendship_generator.rb', line 40

def class_name
  "#{orig_class_name_cam}Friendship"
end

#generate_classObject



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

def generate_class
  template "friendship_model.rb.erb", "app/models/#{model_filename}"
end

#generate_migrationObject



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

def generate_migration
  migration_template "friendship_migration.rb.erb", "db/migrate/#{migration_file_name}"
end

#migration_class_nameObject



25
26
27
# File 'lib/generators/friendship/friendship_generator.rb', line 25

def migration_class_name
  migration_name.camelize
end

#migration_file_nameObject



21
22
23
# File 'lib/generators/friendship/friendship_generator.rb', line 21

def migration_file_name
  "#{migration_name}.rb"
end

#migration_nameObject



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

def migration_name
  "create_#{name.underscore}_friendship"
end

#model_filenameObject



44
45
46
# File 'lib/generators/friendship/friendship_generator.rb', line 44

def model_filename
  "#{orig_class_name_und}_friendship.rb"
end

#orig_class_name_camObject



32
33
34
# File 'lib/generators/friendship/friendship_generator.rb', line 32

def orig_class_name_cam
  "#{name.camelize}"
end

#orig_class_name_undObject



29
30
31
# File 'lib/generators/friendship/friendship_generator.rb', line 29

def orig_class_name_und
  "#{name.underscore.downcase}"
end

#table_nameObject



36
37
38
# File 'lib/generators/friendship/friendship_generator.rb', line 36

def table_name
 ":#{orig_class_name_und}_friendships"
end