Class: Apimaster::Generators::Update

Inherits:
Create show all
Defined in:
lib/apimaster/generators/command.rb

Overview

Update generator’s action manifest.

Constant Summary

Constants inherited from Base

Base::DEFAULT_SHEBANG

Instance Attribute Summary

Attributes inherited from Base

#active, #args, #destination_root, #logger, #source_root, #spec, #stdout

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Create

#class_collisions, #file_copy_each, #folder, #identical?, #migration_template, #readme, #route_resources, #template_copy_each, #write_manifest

Methods inherited from Command

#class_collisions, #dependency, #destination_path, #invoke!, #readme, #source_path, #write_manifest

Methods inherited from Base

#after_generate, #base_name, #camelize, #destination_path, #initialize, #manifest, #pluralize, #run, #source_path

Methods included from Options

included

Constructor Details

This class inherits a constructor from Apimaster::Generators::Base

Instance Method Details

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



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
# File 'lib/apimaster/generators/command.rb', line 669

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(/\.erb/,'')} 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



691
692
693
# File 'lib/apimaster/generators/command.rb', line 691

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

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



661
662
663
# File 'lib/apimaster/generators/command.rb', line 661

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

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



665
666
667
# File 'lib/apimaster/generators/command.rb', line 665

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