5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/generators/model_gen/define_relations/define_relations_generator.rb', line 5
def create
attributes.each do |relation|
line = "class #{name.downcase.capitalize} < ApplicationRecord"
case relation.type
when :has_many
gsub_file "app/models/#{name.downcase}.rb", /(#{Regexp.escape(line)})/mi do |match|
"#{match}\n #{relation.type} :#{relation.name.downcase.pluralize}\n"
end
when :has_one
gsub_file "app/models/#{name.downcase}.rb", /(#{Regexp.escape(line)})/mi do |match|
"#{match}\n #{relation.type} :#{relation.name.downcase}\n"
end
when :has_and_belongs_to_many
puts relation.type
puts relation.name
end
end
end
|