Class: Dbmapper::DatabaseMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/dbmapper.rb

Instance Method Summary collapse

Instance Method Details

#all_columnsObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dbmapper.rb', line 20

def all_columns
	#open file
	text_file = File.open("mapped_databse.txt", 'w')
	ActiveRecord::Base.descendants.each do |model|
		text_file.write(model + '\n');
		model.column_names.each do |column|
			text_file.write(column)
		end
	end
	puts "All your columns have been written to mapped_databse.txt"
	text_file.close
end

#all_modelsObject



10
11
12
13
14
15
16
17
18
# File 'lib/dbmapper.rb', line 10

def all_models
	#open file
	text_file = File.open("mapped_databse.txt", 'w')
	ActiveRecord::Base.descendants.each do |model|
		text_file.write(model + '\n')
	end
	puts "All your models have been written to mapped_databse.txt"
	text_file.close
end

#all_models_with_associationObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dbmapper.rb', line 33

def all_models_with_association
	#open file
	text_file = File.open("mapped_databse.txt", 'w')
	association_string = "-->"
	ActiveRecord::Base.descendants.each do |model|
		text_file.write(model + '\n')
		model.relfect_on_all_associations.map(&:name).each do |assocations|
			association_string = association_string + " #{assocations},"
		end 
		text_file.write(association_string + '\n')
		association_string = "-->"
	end
	puts "all models with their assocations have been written to mapped_databse.txt"
	text_file.close
end

#initlializeObject



6
7
8
# File 'lib/dbmapper.rb', line 6

def initlialize
	Rails.application.eager_load!
end