Class: Rails::Generator::Commands::Update

Inherits:
Create show all
Defined in:
lib/rails_generator/commands.rb

Overview

Update generator’s action manifest.

Instance Attribute Summary

Attributes inherited from Base

#args, #destination_root, #source_root

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Create

#class_collisions, #identical?, #migration_template, #readme, #route_resources

Methods inherited from Base

#class_collisions, #dependency, #invoke!, #readme

Methods inherited from Base

#destination_path, #initialize, #manifest, #source_path

Methods included from Options

included

Constructor Details

This class inherits a constructor from Rails::Generator::Base

Instance Method Details

#complex_template(relative_source, relative_destination, template_options = {}) ⇒ Object



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/rails_generator/commands.rb', line 553

def complex_template(relative_source, relative_destination, template_options = {})

   begin
     dest_file = destination_path(relative_destination)
     source_to_update = File.readlines(dest_file).join
   rescue Errno::ENOENT
     logger.missing relative_destination
     return
   end

   logger.refreshing "#{template_options[:insert].gsub(/\.rhtml/,'')} inside #{relative_destination}"

   begin_mark = Regexp.quote(template_part_mark(template_options[:begin_mark], template_options[:mark_id]))
   end_mark = Regexp.quote(template_part_mark(template_options[:end_mark], template_options[:mark_id]))

   # Refreshing inner part of the template with freshly rendered part.
   rendered_part = render_template_part(template_options)
   source_to_update.gsub!(/#{begin_mark}.*?#{end_mark}/m, rendered_part)

   File.open(dest_file, 'w') { |file| file.write(source_to_update) }
end

#directory(relative_path) ⇒ Object



575
576
577
# File 'lib/rails_generator/commands.rb', line 575

def directory(relative_path)
  # logger.directory "#{destination_path(relative_path)}/"
end

#file(relative_source, relative_destination, options = {}) ⇒ Object



545
546
547
# File 'lib/rails_generator/commands.rb', line 545

def file(relative_source, relative_destination, options = {})
  # logger.file relative_destination
end

#template(relative_source, relative_destination, options = {}) ⇒ Object



549
550
551
# File 'lib/rails_generator/commands.rb', line 549

def template(relative_source, relative_destination, options = {})
  # logger.template relative_destination
end