Sha256: 3815b25a8dbe19f68fd41d063b041f06a169385d7cd7873058964e05a8533c0b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

Rails::Generator::Commands::Create.class_eval do
  def insert_after(file, sentinel, line)
    logger.insert "#{line} into #{file}"
    unless options[:pretend]
      gsub_file file, /(#{Regexp.escape(sentinel)})/mi do |match|
        "#{match}\n  #{line}"
      end
    end
  end

  def replace(file, str1, str2)
    logger.replace "#{str1} with #{str2}"
    unless options[:pretend]
      gsub_file file, "#{str1}", "#{str2}"
    end
  end
end

Rails::Generator::Commands::Destroy.class_eval do
  def insert_after(file, sentinel, line)
    logger.remove "#{line} from #{file}"
    unless options[:pretend]
      gsub_file file, "\n  #{line}", ''
    end
  end

  def replace(file, str1, str2)
    logger.restore "#{str2} from #{str1}"
    unless options[:pretend]
      gsub_file file, "#{str2}", "#{str2}"
    end
  end
end

Rails::Generator::Commands::List.class_eval do
  def insert_after(file, sentinel, line)
    logger.insert "#{line} into #{file}"
  end

  def replace(file, str1, str2)
    logger.replace "#{str1} with #{str2}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ghart-nifty-generators-0.3.0.1 rails_generators/nifty_layout/lib/insert_commands.rb