Class: RubyAPI::Application
- Inherits:
-
Object
- Object
- RubyAPI::Application
- Defined in:
- lib/ruby_api/application.rb
Overview
Application
Constant Summary collapse
- APP_MODULE_NAME =
'APP'- APP_SOURCE_PATH =
'src/main'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #app_module ⇒ Object
- #boot ⇒ Object
- #call(env) ⇒ Object
-
#initialize(config) ⇒ Application
constructor
A new instance of Application.
- #load_routes ⇒ Object
Constructor Details
#initialize(config) ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 |
# File 'lib/ruby_api/application.rb', line 11 def initialize(config) raise "Invalid config: #{config.inspect}" unless config.is_a?(Config) @config = config @routes = load_routes end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/ruby_api/application.rb', line 9 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/ruby_api/application.rb', line 9 def logger @logger end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
9 10 11 |
# File 'lib/ruby_api/application.rb', line 9 def routes @routes end |
Instance Method Details
#app_module ⇒ Object
43 44 45 |
# File 'lib/ruby_api/application.rb', line 43 def app_module Kernel.const_get(app_name) end |
#boot ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_api/application.rb', line 26 def boot @logger = Logger.new log_path[:info] @logger_err = Logger.new log_path[:error] require RubyAPI.path(boot_script) if boot_script? require RubyAPI.path(app_path) self end |
#call(env) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/ruby_api/application.rb', line 34 def call(env) @env = env response = process Request.new(self, env, routes) return handle_error(response) if response.failure? handle_success(response) rescue StandardError => e handle_exception(e) end |
#load_routes ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ruby_api/application.rb', line 17 def load_routes return {} unless config.key?(:routes) routes = config.routes require_hash_or_string(routes, 'Invalid routes config: %s') routes = YAML.load_file RubyAPI.path(routes) if routes.is_a?(String) @routes = routes.deep_symbolize_keys! end |