Class: ModuleGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- ModuleGenerator
- Includes:
- ModuleHelper
- Defined in:
- lib/generators/module/module_generator.rb
Instance Method Summary collapse
- #create_additional_files ⇒ Object
- #create_directory_structure ⇒ Object
- #create_engine ⇒ Object
-
#update_and_install ⇒ Object
:nocov:.
- #update_gemfile ⇒ Object
- #update_routes_file ⇒ Object
- #update_simplecov_helper ⇒ Object
-
#update_spec_helper ⇒ Object
rubocop:disable Rails/Output.
Methods included from ModuleHelper
Instance Method Details
#create_additional_files ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/module/module_generator.rb', line 25 def create_additional_files path = "modules/#{file_name}" # create rakefile template 'Rakefile.erb', File.join(path, 'Rakefile') # create readme template 'README.rdoc.erb', File.join(path, 'README.rdoc') # create bin/rails template 'bin/rails.erb', File.join(path, 'bin', 'rails') chmod File.join(path, 'bin', 'rails'), 0o755 # /spec/spec_helper template 'spec/spec_helper.rb.erb', File.join(path, 'spec', 'spec_helper.rb') # create the routes file template 'config/routes.rb.erb', File.join(path, 'config', 'routes.rb') # create gemspec template 'gemspec.erb', File.join(path, "#{file_name}.gemspec") # create gemfile template 'Gemfile.erb', File.join(path, 'Gemfile') end |
#create_directory_structure ⇒ Object
10 11 12 13 14 15 |
# File 'lib/generators/module/module_generator.rb', line 10 def create_directory_structure # create the dir structure here %w[controllers models serializers services].each do |dir| FileUtils.mkdir_p "modules/#{file_name}/app/#{dir}" unless Dir.exist?("modules/#{file_name}/app/#{dir}") end end |
#create_engine ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/generators/module/module_generator.rb', line 17 def create_engine # create engine file path = "modules/#{file_name}/lib" template 'lib/namespace/engine.rb.erb', File.join(path, file_name, 'engine.rb') template 'lib/namespace/version.rb.erb', File.join(path, file_name, 'version.rb') template 'lib/namespace.rb.erb', File.join(path, "#{file_name}.rb") end |
#update_and_install ⇒ Object
:nocov:
92 93 94 95 |
# File 'lib/generators/module/module_generator.rb', line 92 def update_and_install run 'bundle install' puts "\n\u{1F64C} new module generated at ./modules/#{file_name}\n\n\n" end |
#update_gemfile ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/generators/module/module_generator.rb', line 74 def update_gemfile = {} [:insert_matcher] = "gem '#{file_name}'" [:new_entry] = " #{[:insert_matcher]}\n" module_generator_file_insert('Gemfile', ) end |
#update_routes_file ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/generators/module/module_generator.rb', line 82 def update_routes_file = {} [:regex] = /# Modules(.*)# End Modules/m [:insert_matcher] = "mount #{file_name.camelize}::Engine, at: '/#{file_name}'" [:new_entry] = " mount #{file_name.camelize}::Engine, at: '/#{file_name}'\n" module_generator_file_insert('config/routes.rb', ) end |
#update_simplecov_helper ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/generators/module/module_generator.rb', line 62 def update_simplecov_helper # spec and simplecov helper add group = {} [:regex] = /# Modules(.*)end/m [:insert_matcher] = "add_group '#{file_name.camelize}', 'modules/#{file_name}/'" [:new_entry] = " add_group '#{file_name.camelize}', " \ "'modules/#{file_name}/'\n" module_generator_file_insert('spec/simplecov_helper.rb', ) end |
#update_spec_helper ⇒ Object
rubocop:disable Rails/Output
52 53 54 55 56 57 58 59 60 |
# File 'lib/generators/module/module_generator.rb', line 52 def update_spec_helper = {} [:regex] = /# Modules(.*)# End Modules/m [:insert_matcher] = "add_group '#{file_name.camelize}', 'modules/#{file_name}/'" [:new_entry] = " add_group '#{file_name.camelize}', " \ "'modules/#{file_name}/'\n" module_generator_file_insert('spec/spec_helper.rb', ) end |