Class: Kangaru::Application

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

Defined Under Namespace

Classes: InvalidConfigError

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject

Returns the value of attribute config_path.



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

def config_path
  @config_path
end

#databaseObject (readonly)

Returns the value of attribute database.



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

def database
  @database
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#pathsObject (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

#configObject

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

Returns:

  • (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

#routerObject



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