Module: Jets::Core

Extended by:
Memoist
Included in:
Jets
Defined in:
lib/jets/core.rb

Constant Summary collapse

@@application =

Calling application triggers load of configs. Jets’ the default config/application.rb is loaded, then the project’s config/application.rb is loaded.

nil
@@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

Instance Method Details

#applicationObject



12
13
14
15
16
17
18
# File 'lib/jets/core.rb', line 12

def application
  return @@application if @@application

  @@application = Jets::Application.new
  @@application.setup!
  @@application
end

#awsObject



26
27
28
# File 'lib/jets/core.rb', line 26

def aws
  application.aws
end

#boot(options = {}) ⇒ Object

Load all application base classes and project classes



31
32
33
# File 'lib/jets/core.rb', line 31

def boot(options={})
  Jets::Booter.boot!(options)
end

#build_rootObject



62
63
64
# File 'lib/jets/core.rb', line 62

def build_root
  "/tmp/jets/#{config.project_name}".freeze
end

#call_countObject



106
107
108
# File 'lib/jets/core.rb', line 106

def call_count
  @@call_count
end

#configObject

For some reason memoize doesnt work with application, think there’s some circular dependency issue. Figure this out later.



22
23
24
# File 'lib/jets/core.rb', line 22

def config
  application.config
end

#eager_load!Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jets/core.rb', line 85

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

#envObject



55
56
57
58
59
# File 'lib/jets/core.rb', line 55

def env
  env = ENV['JETS_ENV'] || 'development'
  ENV['RAILS_ENV'] = ENV['RACK_ENV'] = env
  ActiveSupport::StringInquirer.new(env)
end

#increase_call_countObject



102
103
104
# File 'lib/jets/core.rb', line 102

def increase_call_count
  @@call_count += 1
end

#increase_prewarm_countObject



111
112
113
# File 'lib/jets/core.rb', line 111

def increase_prewarm_count
  @@prewarm_count += 1
end

#load_tasksObject



77
78
79
# File 'lib/jets/core.rb', line 77

def load_tasks
  Jets::Commands::RakeTasks.load!
end

#loggerObject



67
68
69
# File 'lib/jets/core.rb', line 67

def logger
  Logger.new($stderr)
end

#prewarm_countObject



115
116
117
# File 'lib/jets/core.rb', line 115

def prewarm_count
  @@prewarm_count
end

#rootObject

Ensures trailing slash Useful for appending a ‘./’ in front of a path or leaving it alone. Returns: ‘/path/with/trailing/slash/’ or ‘./’ @@root = nil def root

return @@root if @@root
@@root = ENV['JETS_ROOT'].to_s
@@root = '.' if @@root == ''
@@root = "#{@@root}/" unless @@root.ends_with?('/')
@@root = Pathname.new(@@root)

end



47
48
49
50
51
52
# File 'lib/jets/core.rb', line 47

def root
  root = ENV['JETS_ROOT'].to_s
  root = '.' if root == ''
  root = "#{root}/" unless root.ends_with?('/')
  Pathname.new(root)
end

#versionObject



81
82
83
# File 'lib/jets/core.rb', line 81

def version
  Jets::VERSION
end

#webpacker?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/jets/core.rb', line 72

def webpacker?
  Gem.loaded_specs.keys.include?("webpacker")
end