class Suspenders::PreloaderGenerator
Public Instance Methods
cache_classes_test()
click to toggle source
# File lib/suspenders/generators/preloader_generator.rb, line 20 def cache_classes_test action UncacheClasses.new(self, "config/environments/test.rb") end
spring_binstubs()
click to toggle source
# File lib/suspenders/generators/preloader_generator.rb, line 24 def spring_binstubs action SpringBinstubs.new(self) end
spring_config()
click to toggle source
# File lib/suspenders/generators/preloader_generator.rb, line 5 def spring_config template "spring.rb", "config/spring.rb", force: false, skip: true end
spring_gem()
click to toggle source
# File lib/suspenders/generators/preloader_generator.rb, line 9 def spring_gem always_gsub_file("Gemfile", /# Spring speeds up development.*/, "") gem_group :development do gem "spring" gem "spring-watcher-listen", "~> 2.0.0" end Bundler.with_unbundled_env { run "bundle install" } end
Protected Instance Methods
always_gsub_file(path, flag, replacement, verbose: true)
click to toggle source
# File lib/suspenders/generators/preloader_generator.rb, line 111 def always_gsub_file(path, flag, replacement, verbose: true) path = File.expand_path(path, destination_root) say_status :gsub, relative_to_original_destination_root(path), verbose unless options[:pretend] content = File.binread(path) content.gsub!(flag, replacement) File.open(path, "wb") { |file| file.write(content) } end end
always_run(command, with: nil, verbose: true, env: nil, capture: nil, abort_on_failure: nil)
click to toggle source
# File lib/suspenders/generators/preloader_generator.rb, line 73 def always_run(command, with: nil, verbose: true, env: nil, capture: nil, abort_on_failure: nil) destination = relative_to_original_destination_root( destination_root, false ) desc = "#{command} from #{destination.inspect}" if with desc = "#{File.basename(with.to_s)} #{desc}" command = "#{with} #{command}" end say_status :run, desc, verbose return if options[:pretend] env_splat = [env] if env if capture result, status = Open3.capture2e(*env_splat, command.to_s) success = status.success? else result = system(*env_splat, command.to_s) success = result end if abort_on_failure.nil? abort_on_failure = self.class.send(:exit_on_failure?) end if !success && abort_on_failure abort end result end