Class: Kangaru::Application

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/kangaru/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, namespace:) ⇒ Application

Returns a new instance of Application.



7
8
9
10
11
12
# File 'lib/kangaru/application.rb', line 7

def initialize(source:, namespace:)
  @paths = Paths.new(source:)
  @namespace = namespace

  autoloader.setup
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



5
6
7
# File 'lib/kangaru/application.rb', line 5

def database
  @database
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/kangaru/application.rb', line 5

def namespace
  @namespace
end

#pathsObject (readonly)

Returns the value of attribute paths.



5
6
7
# File 'lib/kangaru/application.rb', line 5

def paths
  @paths
end

Instance Method Details

#apply_config!Object



30
31
32
33
34
35
36
37
# File 'lib/kangaru/application.rb', line 30

def apply_config!
  raise "config already applied" if configured?

  config.import_external_config!

  @database = setup_database!
  @configured = true
end

#configObject

Lazy-loaded to allow defaults to be set after application is created.



15
16
17
# File 'lib/kangaru/application.rb', line 15

def config
  @config ||= Config.new
end

#configure(env = nil, &block) ⇒ Object

If called with no env, the config will be applied regardless of current env. If multiple configure calls matching the current env are made, the most recent calls will overwrite older changes.



22
23
24
# File 'lib/kangaru/application.rb', line 22

def configure(env = nil, &block)
  block.call(config) if current_env?(env)
end

#configured?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/kangaru/application.rb', line 26

def configured?
  @configured == true
end

#run!(*argv) ⇒ Object



39
40
41
42
43
# File 'lib/kangaru/application.rb', line 39

def run!(*argv)
  request = RequestBuilder.new(argv).build

  Router.new(request, namespace:).resolve
end