template.rb
# Add template directory to source_paths so that Thor can resolve actions like
# `copy_file` and `template` regardless of if invoked locally or remotely via
# HTTPS. If files are not present, clone them to a local tmp directory.
Add template directory to source_paths so that Thor can resolve actions like
`copy_file` and `template` regardless of if invoked locally or remotely via
HTTPS. If files are not present, clone them to a local tmp directory.
Add template directory to source_paths so that Thor can resolve actions like ` copy_file ` and ` template ` regardless of if invoked locally or remotely via HTTPS . If files are not present clone them to a local tmp directory .
def add_template_files_to_tmp_path
  if __FILE__ =~ %r{\Ahttps:\/\/}
    require 'tmpdir'
    source_paths.unshift(tempdir = Dir.mktmpdir('rails-template-'))
    at_exit { FileUtils.remove_entry(tempdir) }
    git clone: [
      '--quiet',
      RAILS_TEMPLATE_REPO,
      tempdir
    ].map(&:shellescape).join(' ')
    if (branch = __FILE__[%r{rails-template/(.+)/template.rb}, 1])
      Dir.chdir(tempdir) { git checkout: branch }
    end
  elsif __FILE__ =~ %r{\Ahttp:\/\/}
    raise Rails::Generators::Error,
      'Please use HTTPS instead of HTTP for fetching this script!'
  else
    source_paths.unshift(File.dirname(__FILE__))
  end
end
def add_template_files_to_tmp_path if __FILE__ =~ %r{ \A https: \/ \/ } require 'tmpdir' source_paths . unshift ( tempdir = Dir . mktmpdir ( 'rails-template-' ) ) at_exit { FileUtils . remove_entry ( tempdir ) } git clone : [ '--quiet' , RAILS_TEMPLATE_REPO , tempdir ] . map ( & :shellescape ) . join ( ' ' ) if ( branch = __FILE__ [ %r{ rails-template/(.+)/template.rb } , 1 ] ) Dir . chdir ( tempdir ) { git checkout : branch } end elsif __FILE__ =~ %r{ \A http: \/ \/ } raise Rails :: Generators :: Error , 'Please use HTTPS instead of HTTP for fetching this script!' else source_paths . unshift ( File . dirname ( __FILE__ ) ) end end
Add template directory to source_paths so that Thor can resolve actions like
`copy_file` and `template` regardless of if invoked locally or remotely via
HTTPS.
Add template directory to source_paths so that Thor can resolve actions like ` copy_file ` and ` template ` regardless of if invoked locally or remotely via HTTPS .
# Fetch and checkout branch name from filepath