Module: GeneratorHelper
- Included in:
- ReactOnRails::Generators::BaseGenerator, ReactOnRails::Generators::BootstrapGenerator, ReactOnRails::Generators::DevTestsGenerator, ReactOnRails::Generators::HerokuDeploymentGenerator, ReactOnRails::Generators::InstallGenerator, ReactOnRails::Generators::ReactNoReduxGenerator, ReactOnRails::Generators::RubyLintersGenerator
- Defined in:
- lib/generators/react_on_rails/generator_helper.rb
Instance Method Summary collapse
- #copy_file_and_missing_parent_directories(source_file, destination_file = nil) ⇒ Object
- #dest_dir_exists?(dir) ⇒ Boolean
-
#dest_file_exists?(file) ⇒ Boolean
Takes a relative path from the destination root, such as ‘.gitignore` or `app/assets/javascripts/application.js`.
- #empty_directory_with_keep_file(destination, config = {}) ⇒ Object
- #keep_file(destination) ⇒ Object
- #setup_file_error(file, data) ⇒ Object
-
#symlink_dest_file_to_dest_file(target, link) ⇒ Object
As opposed to Rails::Generators::Testing.create_link, which creates a link pointing to source_root, this symlinks a file in destination_root to a file also in destination_root.
Instance Method Details
#copy_file_and_missing_parent_directories(source_file, destination_file = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 46 def copy_file_and_missing_parent_directories(source_file, destination_file = nil) destination_file = source_file unless destination_file destination_path = Pathname.new(destination_file) parent_directories = destination_path.dirname empty_directory(parent_directories) unless dest_dir_exists?(parent_directories) copy_file source_file, destination_file end |
#dest_dir_exists?(dir) ⇒ Boolean
10 11 12 13 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 10 def dest_dir_exists?(dir) dest_dir = File.join(destination_root, dir) Dir.exist?(dest_dir) ? dest_dir : nil end |
#dest_file_exists?(file) ⇒ Boolean
Takes a relative path from the destination root, such as ‘.gitignore` or `app/assets/javascripts/application.js`
5 6 7 8 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 5 def dest_file_exists?(file) dest_file = File.join(destination_root, file) File.exist?(dest_file) ? dest_file : nil end |
#empty_directory_with_keep_file(destination, config = {}) ⇒ Object
23 24 25 26 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 23 def empty_directory_with_keep_file(destination, config = {}) empty_directory(destination, config) keep_file(destination) end |
#keep_file(destination) ⇒ Object
28 29 30 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 28 def keep_file(destination) create_file("#{destination}/.keep") unless [:skip_keeps] end |
#setup_file_error(file, data) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 15 def setup_file_error(file, data) <<-MSG #{file} was not found. Please add the following content to your #{file} file: #{data} MSG end |
#symlink_dest_file_to_dest_file(target, link) ⇒ Object
As opposed to Rails::Generators::Testing.create_link, which creates a link pointing to source_root, this symlinks a file in destination_root to a file also in destination_root.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/react_on_rails/generator_helper.rb', line 35 def symlink_dest_file_to_dest_file(target, link) target_pathname = Pathname.new(File.join(destination_root, target)) link_pathname = Pathname.new(File.join(destination_root, link)) link_directory = link_pathname.dirname link_basename = link_pathname.basename target_relative_path = target_pathname.relative_path_from(link_directory) `cd #{link_directory} && ln -s #{target_relative_path} #{link_basename}` end |