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
48 49 50 51 52 |
# File 'lib/grape/app.rb', line 48 def autoload(paths) paths.each do |path| Object.autoload ActiveSupport::Inflector.classify(path), path end end |
.env ⇒ ActiveSupport::StringInquirer
Returns env name.
44 45 46 |
# File 'lib/grape/app.rb', line 44 def env @env ||= ActiveSupport::StringInquirer.new(ENV['GRAPE_ENV'] || ENV['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 |
# 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 # Load initializers require 'grape/app/initializers/pre' require_one 'config', 'environments', env require_all 'config', 'initializers' require 'grape/app/initializers/post' # Load app $LOAD_PATH.push @root.join('lib') $LOAD_PATH.push @root.join('app') $LOAD_PATH.push @root.join('app', 'models') require_one 'app', 'models' require_one 'app', 'api' end |
.middleware ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/grape/app.rb', line 54 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.
39 40 41 |
# File 'lib/grape/app.rb', line 39 def root @root ||= Bundler.root.dup end |