Class: Kangaru::Application
- Inherits:
-
Object
- Object
- Kangaru::Application
- Extended by:
- Forwardable
- Defined in:
- lib/kangaru/application.rb
Defined Under Namespace
Classes: InvalidConfigError
Instance Attribute Summary collapse
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #apply_config! ⇒ Object
-
#config ⇒ Object
Lazy-loaded to allow defaults to be set after application is created.
- #configure(&block) ⇒ Object
- #configured? ⇒ Boolean
- #const_get(const) ⇒ Object
-
#initialize(source:, namespace:) ⇒ Application
constructor
A new instance of Application.
- #router ⇒ Object
- #run!(*argv) ⇒ Object
Constructor Details
#initialize(source:, namespace:) ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 16 |
# File 'lib/kangaru/application.rb', line 11 def initialize(source:, namespace:) @paths = Paths.new(source:) @namespace = namespace autoloader.setup end |
Instance Attribute Details
#config_path ⇒ Object
Returns the value of attribute config_path.
9 10 11 |
# File 'lib/kangaru/application.rb', line 9 def config_path @config_path end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
7 8 9 |
# File 'lib/kangaru/application.rb', line 7 def database @database end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/kangaru/application.rb', line 7 def namespace @namespace end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
7 8 9 |
# File 'lib/kangaru/application.rb', line 7 def paths @paths end |
Instance Method Details
#apply_config! ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kangaru/application.rb', line 35 def apply_config! raise "config already applied" if configured? config.import!(config_path) unless config_path.nil? validate_config! @database = setup_database! @configured = true end |
#config ⇒ Object
Lazy-loaded to allow defaults to be set after application is created.
19 20 21 |
# File 'lib/kangaru/application.rb', line 19 def config @config ||= Config.new end |
#configure(&block) ⇒ Object
27 28 29 |
# File 'lib/kangaru/application.rb', line 27 def configure(&block) block.call(config) end |
#configured? ⇒ Boolean
31 32 33 |
# File 'lib/kangaru/application.rb', line 31 def configured? @configured == true end |
#const_get(const) ⇒ Object
52 53 54 55 56 |
# File 'lib/kangaru/application.rb', line 52 def const_get(const) return unless namespace.const_defined?(const) namespace.const_get(const) end |
#router ⇒ Object
23 24 25 |
# File 'lib/kangaru/application.rb', line 23 def router @router ||= Router.new(namespace:) end |
#run!(*argv) ⇒ Object
46 47 48 49 50 |
# File 'lib/kangaru/application.rb', line 46 def run!(*argv) request = RequestBuilder.new(argv).build router.resolve(request) end |