lib/jets/core.rb in jets-0.5.2 vs lib/jets/core.rb in jets-0.5.3

- old
+ new

@@ -75,7 +75,41 @@ end def version Jets::VERSION end + + def eager_load! + Dir.glob("#{Jets.root}app/**/*.rb").select do |path| + next if !File.file?(path) or path =~ %r{/javascript/} or path =~ %r{/views/} + + class_name = path + .sub(/\.rb$/,'') # remove .rb + .sub(/^\.\//,'') # remove ./ + .sub(/app\/\w+\//,'') # remove app/controllers or app/jobs etc + .classify + puts "eager_load! loading path: #{path} class_name: #{class_name}" if ENV['DEBUG'] + class_name.constantize # dont have to worry about order. + end + end + + # NOTE: In development this will always be 1 because the app gets reloaded. + # On AWS Lambda, this will be ever increasing until the container gets replaced. + @@call_count = 0 + def increase_call_count + @@call_count += 1 + end + + def call_count + @@call_count + end + + @@prewarm_count = 0 + def increase_prewarm_count + @@prewarm_count += 1 + end + + def prewarm_count + @@prewarm_count + end end