class BaseGenerator
Constants
- API_CONTROLLER_PATH
- SERIALIZERS
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/generators/base_generator.rb, line 11 def self.exit_on_failure? true end
Private Instance Methods
copy_api_controller()
click to toggle source
Adds an ApiController
if one does not exist to ensure proper encapsulation, especially if in a Rails monolith with Rails HTML views as well
# File lib/generators/base_generator.rb, line 31 def copy_api_controller puts set_color('Checking if an ApiController exists...', :cyan) unless File.exists?('app/controllers/api_controller.rb') puts set_color('ApiController not present, creating ApiController...', :cyan) template 'api_controller.rb', API_CONTROLLER_PATH end end
helper_include(serializer)
click to toggle source
# File lib/generators/base_generator.rb, line 40 def helper_include(serializer) copy_api_controller gsub_file(API_CONTROLLER_PATH, /^*(include DrySerialization::.*)\n/, '') puts 'Adding include statement to ApiController' insert_into_file(API_CONTROLLER_PATH, "\n\tinclude DrySerialization::#{serializer}", after: 'class ApiController < ActionController::API' ) end
log_statement(serializer, color = :green)
click to toggle source
# File lib/generators/base_generator.rb, line 50 def log_statement(serializer, color = :green) puts set_color("Removed #{serializer}", color) end
remove_other_supported_gems(*gems)
click to toggle source
Removes other serialization gems, currently just AMS and JsonapiSerializer
# File lib/generators/base_generator.rb, line 18 def remove_other_supported_gems(*gems) gems = [gems] unless gems.is_a?(Array) return if gems.empty? gems.each do |gem| log_statement(gem, :yellow) gsub_file('Gemfile', /^(\ngem #{gem.underscore})/, '') end end