Class: AssociatedGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/associated/associated_generator.rb

Instance Method Summary collapse

Instance Method Details

#connect_associated_objectObject



9
10
11
12
13
14
15
16
17
# File 'lib/generators/associated/associated_generator.rb', line 9

def connect_associated_object
  record_file = "#{destination_root}/app/models/#{record_path}.rb"

  raise "Record class '#{record_klass}' does not exist" unless File.exist?(record_file)

  inject_into_class record_file, record_klass do
    optimize_indentation "has_object :#{associated_object_path}", 2
  end
end

#generate_associated_object_filesObject



4
5
6
7
# File 'lib/generators/associated/associated_generator.rb', line 4

def generate_associated_object_files
  template "associated.rb",      "app/models/#{name.underscore}.rb"
  template "associated_test.rb", "test/models/#{name.underscore}_test.rb"
end