Class: Grape::App
- Inherits:
-
API
- Object
- API
- Grape::App
- Defined in:
- lib/grape/app.rb
Class Method Summary collapse
-
.config ⇒ Grape::App::Configuration
The configuration.
-
.configure {|config| ... } ⇒ Object
Configure the app.
-
.env ⇒ ActiveSupport::StringInquirer
Env name.
-
.init!(root = nil) ⇒ Object
Run initializers.
-
.loader ⇒ Zeitwerk::Loader
Loader.
- .middleware ⇒ Object
-
.root ⇒ Pathname
Root path.
Class Method Details
.config ⇒ Grape::App::Configuration
Returns the configuration.
45 46 47 48 49 50 51 |
# File 'lib/grape/app.rb', line 45 def config @config ||= if respond_to?(:superclass) && superclass.respond_to?(:config) superclass.config.inheritable_copy else Class.new(Grape::App::Configuration).new end end |
.configure {|config| ... } ⇒ Object
Configure the app
54 55 56 |
# File 'lib/grape/app.rb', line 54 def configure yield config end |
.env ⇒ ActiveSupport::StringInquirer
Returns env name.
64 65 66 |
# File 'lib/grape/app.rb', line 64 def env @env ||= ActiveSupport::StringInquirer.new(ENV.fetch('GRAPE_ENV') { ENV.fetch('RACK_ENV', 'development') }) end |
.init!(root = nil) ⇒ Object
Run initializers
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/grape/app.rb', line 17 def init!(root = nil) @root = Pathname.new(root) if root # Require bundle Bundler.require :default, env.to_sym # Update load path $LOAD_PATH.push self.root.join('lib').to_s # Push dirs to loader push_dir? self.root.join('app') push_dir? self.root.join('app', 'models') # Load initializers require 'grape/app/initializers/pre' require_one 'config', 'environments', env require_all 'config', 'initializers' require 'grape/app/initializers/post' # Setup loader loader.setup # Load app require_one 'app', 'api' Zeitwerk::Loader.eager_load_all if Grape::App.config.eager_load end |
.loader ⇒ Zeitwerk::Loader
Returns loader.
69 70 71 72 73 |
# File 'lib/grape/app.rb', line 69 def loader @loader ||= Zeitwerk::Loader.new.tap do |l| l.inflector = Grape::App::Inflector.new end end |
.middleware ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/grape/app.rb', line 75 def middleware config = self.config @middleware ||= Rack::Builder.new do use Rack::Cors, &config.cors if config.cors if config.force_ssl.is_a?(Hash) use Rack::SslEnforcer, **config.force_ssl elsif config.force_ssl use Rack::SslEnforcer end config.middleware.each do |block| instance_eval(&block) end use Grape::App::Middleware::ConnectionManagement if defined?(ActiveRecord) run Grape::App end end |
.root ⇒ Pathname
Returns root path.
59 60 61 |
# File 'lib/grape/app.rb', line 59 def root @root ||= Bundler.root.dup end |