Class: Grape::App
- Inherits:
-
API
- Object
- API
- Grape::App
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/grape/app.rb
Class Method Summary collapse
- .autoload(paths) ⇒ Object
-
.env ⇒ ActiveSupport::StringInquirer
Env name.
-
.init!(root = nil) ⇒ Object
Run initializers.
- .middleware ⇒ Object
-
.root ⇒ Pathname
Root path.
Class Method Details
.autoload(paths) ⇒ Object
51 52 53 54 55 |
# File 'lib/grape/app.rb', line 51 def autoload(paths) paths.each do |path| Object.autoload ActiveSupport::Inflector.classify(path), path end end |
.env ⇒ ActiveSupport::StringInquirer
Returns env name.
47 48 49 |
# File 'lib/grape/app.rb', line 47 def env @env ||= ActiveSupport::StringInquirer.new(ENV['GRAPE_ENV'] || ENV['RACK_ENV'] || 'development') end |
.init!(root = nil) ⇒ Object
Run initializers
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/grape/app.rb', line 19 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 $LOAD_PATH.push self.root.join('app').to_s $LOAD_PATH.push self.root.join('app', 'models').to_s # Load initializers require 'grape/app/initializers/pre' require_one 'config', 'environments', env require_all 'config', 'initializers' require 'grape/app/initializers/post' # Load app require_one 'app', 'models' require_one 'app', 'api' end |
.middleware ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/grape/app.rb', line 57 def middleware config = self.config @middleware ||= Rack::Builder.new do use Rack::SslEnforcer if config.force_ssl use Rack::Cors do allow do origins *Array.wrap(config.cors_allow_origins) resource '*', headers: :any, methods: [:get, :post, :options, :delete, :put] end end if config.cors_allow_origins run Grape::App end end |
.root ⇒ Pathname
Returns root path.
42 43 44 |
# File 'lib/grape/app.rb', line 42 def root @root ||= Bundler.root.dup end |