Sha256: 7a45e8d1137a1008f0a1edd2e6337df506c1def8f6c4b80fcaafe080863f205a
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
BarkestCore::InstallGenerator.class_eval do MissingApplicationMailer = Class.new(::Thor::Error) ## # Patches the ApplicationMailer class to inherit from BarkestCore::ApplicationMailer. def patch_application_mailer app_file = 'app/mailers/application_mailer.rb' dest_source = '::BarkestCore::ApplicationMailerBase' if File.exist?(app_file) regex = /^(?<NAME>\s*class ApplicationMailer\s*<\s*)(?<ORIG>\S+)\s*(?<COMMENT>#.*)?$/ found = false changed = false lines = File.read(app_file).split("\n").map do |line| match = regex.match(line) found = true if match if match && match['ORIG'] != dest_source changed = true "#{match['NAME']}#{dest_source} # #{match['ORIG']} #{match['COMMENT']}" else line end end raise MissingApplicationMailer.new('ApplicationMailer class not found') unless found if changed if ask_for_bool("Your ApplicationMailer does not currently inherit from BarkestCore.\nWould you like to change this?", true) perform "> updating '#{app_file}'..." do File.write app_file, lines.join("\n") end else tell "> '#{app_file}' is unchanged.", :bright_green end else tell "> '#{app_file}' is good.", :bright_green end else if ask_for_bool("Your application is missing an ApplicationMailer.\nWould you like to create one?", true) perform "> creating '#{app_file}'..." do File.write app_file, <<-APPMLR class ApplicationMailer < #{dest_source} # This is your application mailer, it inherits functionality from BarkestCore. end APPMLR end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
barkest_core-1.5.4.0 | lib/generators/barkest_core/actions/02_patch_application_mailer.rb |
barkest_core-1.5.3.0 | lib/generators/barkest_core/actions/02_patch_application_mailer.rb |