Class: Chapter10::Generators::SolutionsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/chapter10/solutions/solutions_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_destroy_action_to_users_resourceObject



10
11
12
13
14
15
# File 'lib/generators/chapter10/solutions/solutions_generator.rb', line 10

def add_destroy_action_to_users_resource
  dest = File.join(Rails.root,'config','routes.rb')
  insert_into_file(dest, :after => %r{:index,\s*:show}) do
    ", :destroy"
  end
end

#add_migrationObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/chapter10/solutions/solutions_generator.rb', line 17

def add_migration
  found_candidate = Dir.glob(File.join(Rails.root,'db','migrate','*_admin_*')).present?

  if (found_candidate &&
      yes?("We found a migration file containing the word '_admin_'. We think you have the correct migration. Do you still way to copy the solution anyway? (yes/no)", :yellow)) \
      or !found_candidate

    src  = File.expand_path("../snippets/migration_add_admin_to_users.rb", __FILE__)
    dest = File.join(Rails.root,'db','migrate',Time.now.strftime("%Y%m%d%H%M%S")+'_add_admin_to_users.rb')
    copy_file(src,dest)
  end
end

#copy_app_treeObject



6
7
8
# File 'lib/generators/chapter10/solutions/solutions_generator.rb', line 6

def copy_app_tree
  directory(self.class.source_root, Rails.root)
end