Module: Jets::Core
Constant Summary collapse
- @@call_count =
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.
0
- @@prewarm_count =
0
Instance Method Summary collapse
- #application ⇒ Object
- #aws ⇒ Object
-
#boot(options = {}) ⇒ Object
Load all application base classes and project classes.
- #build_root ⇒ Object
- #call_count ⇒ Object
- #class_mappings(class_name) ⇒ Object
- #config ⇒ Object
- #custom_domain? ⇒ Boolean
- #eager_load! ⇒ Object
-
#eager_load_app ⇒ Object
Eager load user’s application.
-
#eager_load_jets ⇒ Object
Eager load jet’s lib and classes.
- #env ⇒ Object
- #increase_call_count ⇒ Object
- #increase_prewarm_count ⇒ Object
- #lazy_load? ⇒ Boolean
- #load_tasks ⇒ Object
- #logger ⇒ Object
- #poly_only? ⇒ Boolean
- #prewarm_count ⇒ Object
- #project_namespace ⇒ Object
- #rack? ⇒ Boolean
- #report_exception(exception) ⇒ Object
-
#root ⇒ Object
Ensures trailing slash Useful for appending a ‘./’ in front of a path or leaving it alone.
-
#skip_eager_load_paths?(path) ⇒ Boolean
Skip these paths because eager loading doesnt work for them.
- #version ⇒ Object
- #webpacker? ⇒ Boolean
Instance Method Details
#application ⇒ Object
4 5 6 |
# File 'lib/jets/core.rb', line 4 def application Jets::Application.instance end |
#aws ⇒ Object
12 13 14 |
# File 'lib/jets/core.rb', line 12 def aws application.aws end |
#boot(options = {}) ⇒ Object
Load all application base classes and project classes
17 18 19 |
# File 'lib/jets/core.rb', line 17 def boot(={}) Jets::Booter.boot!() end |
#build_root ⇒ Object
39 40 41 |
# File 'lib/jets/core.rb', line 39 def build_root "/tmp/jets/#{config.project_name}".freeze end |
#call_count ⇒ Object
133 134 135 |
# File 'lib/jets/core.rb', line 133 def call_count @@call_count end |
#class_mappings(class_name) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/jets/core.rb', line 102 def class_mappings(class_name) map = { "Jets::Io" => "Jets::IO", } map[class_name] || class_name end |
#config ⇒ Object
8 9 10 |
# File 'lib/jets/core.rb', line 8 def config application.config end |
#custom_domain? ⇒ Boolean
174 175 176 |
# File 'lib/jets/core.rb', line 174 def custom_domain? Jets.config.domain.hosted_zone_name end |
#eager_load! ⇒ Object
62 63 64 65 |
# File 'lib/jets/core.rb', line 62 def eager_load! eager_load_jets eager_load_app end |
#eager_load_app ⇒ Object
Eager load user’s application
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/jets/core.rb', line 110 def eager_load_app Dir.glob("#{Jets.root}app/**/*.rb").select do |path| next if !File.file?(path) or path =~ %r{/javascript/} or path =~ %r{/views/} next if path.include?('app/functions') || path.include?('app/shared/functions') || path.include?('app/internal/functions') class_name = path .sub(/\.rb$/,'') # remove .rb .sub(%{^\./},'') # remove ./ .sub(Jets.root.to_s,'') .sub(%r{app/shared/\w+/},'') # remove shared/resources or shared/extensions .sub(%r{app/\w+/},'') # remove app/controllers or app/jobs etc class_name = class_name.classify class_name.constantize # use constantize instead of require so dont have to worry about order. end end |
#eager_load_jets ⇒ Object
Eager load jet’s lib and classes
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jets/core.rb', line 68 def eager_load_jets lib_jets = File.(".", File.dirname(__FILE__)) Dir.glob("#{lib_jets}/**/*.rb").select do |path| next if !File.file?(path) next if skip_eager_load_paths?(path) path = path.sub("#{lib_jets}/","jets/") class_name = path .sub(/\.rb$/,'') # remove .rb .sub(/^\.\//,'') # remove ./ .sub(/app\/\w+\//,'') # remove app/controllers or app/jobs etc .camelize # special class mappings class_name = class_mappings(class_name) class_name.constantize # use constantize instead of require so dont have to worry about order. end end |
#env ⇒ Object
32 33 34 35 36 |
# File 'lib/jets/core.rb', line 32 def env env = ENV['JETS_ENV'] || 'development' ENV['RAILS_ENV'] = ENV['RACK_ENV'] = env ActiveSupport::StringInquirer.new(env) end |
#increase_call_count ⇒ Object
129 130 131 |
# File 'lib/jets/core.rb', line 129 def increase_call_count @@call_count += 1 end |
#increase_prewarm_count ⇒ Object
138 139 140 |
# File 'lib/jets/core.rb', line 138 def increase_prewarm_count @@prewarm_count += 1 end |
#lazy_load? ⇒ Boolean
155 156 157 158 |
# File 'lib/jets/core.rb', line 155 def lazy_load? return false if poly_only? # no need to lazy load when poly_only? config.ruby.lazy_load end |
#load_tasks ⇒ Object
54 55 56 |
# File 'lib/jets/core.rb', line 54 def load_tasks Jets::Commands::RakeTasks.load! end |
#logger ⇒ Object
44 45 46 |
# File 'lib/jets/core.rb', line 44 def logger Jets::Logger.new($stderr) end |
#poly_only? ⇒ Boolean
160 161 162 163 |
# File 'lib/jets/core.rb', line 160 def poly_only? return true if ENV['JETS_POLY_ONLY'] # bypass to allow rapid development of handlers Jets::Commands::Build.poly_only? end |
#prewarm_count ⇒ Object
142 143 144 |
# File 'lib/jets/core.rb', line 142 def prewarm_count @@prewarm_count end |
#project_namespace ⇒ Object
146 147 148 |
# File 'lib/jets/core.rb', line 146 def project_namespace [config.project_name, config.short_env, config.env_extra].compact.join('-').gsub('_','-') end |
#rack? ⇒ Boolean
150 151 152 153 |
# File 'lib/jets/core.rb', line 150 def rack? path = "#{Jets.root}rack" File.exist?(path) || File.symlink?(path) end |
#report_exception(exception) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/jets/core.rb', line 165 def report_exception(exception) Jets::Turbine.subclasses.each do |subclass| reporters = subclass.exception_reporters || [] reporters.each do |label, block| block.call(exception) end end end |
#root ⇒ Object
Ensures trailing slash Useful for appending a ‘./’ in front of a path or leaving it alone. Returns: ‘/path/with/trailing/slash/’ or ‘./’
24 25 26 27 28 29 |
# File 'lib/jets/core.rb', line 24 def root root = ENV['JETS_ROOT'].to_s root = '.' if root == '' root = "#{root}/" unless root.ends_with?('/') Pathname.new(root) end |
#skip_eager_load_paths?(path) ⇒ Boolean
Skip these paths because eager loading doesnt work for them.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/jets/core.rb', line 87 def skip_eager_load_paths?(path) path =~ %r{/cli} || path =~ %r{/core_ext} || path =~ %r{/default/application} || path =~ %r{/functions} || path =~ %r{/internal/app} || path =~ %r{/jets/stack} || path =~ %r{/rackup_wrappers} || path =~ %r{/rails_overrides} || path =~ %r{/reconfigure_rails} || path =~ %r{/templates/} || path =~ %r{/version} || path =~ %r{/webpacker} end |
#webpacker? ⇒ Boolean
49 50 51 |
# File 'lib/jets/core.rb', line 49 def webpacker? Gem.loaded_specs.keys.include?("webpacker") end |