Class: Chapter11_3::Generators::SolutionsGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_feed_method_to_userObject



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

def add_feed_method_to_user
  dest = File.join(Rails.root, 'app', 'models', 'user.rb')
  insert_into_file(dest, :before => /end\s*\Z/) do # insert before end
    <<-CODE.gsub(/^\s+\|/,'  ')
      |def feed
      |  microposts
      |end
    CODE
  end
end

#add_microposts_resourceObject



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

def add_microposts_resource
  dest = File.join(Rails.root,'config','routes.rb')
  insert_into_file(dest, :after => %r{resources\s+:users.*$}) do
    "\n  resources :microposts, :only => [:create, :destroy]"
  end
end

#copy_app_treeObject



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

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