Class: Charyf::Application

Inherits:
AppEngine show all
Includes:
Initializable
Defined in:
lib/charyf/utils/application.rb,
lib/charyf/utils/application/bootstrap.rb,
lib/charyf/utils/application/configuration.rb

Defined Under Namespace

Modules: Bootstrap Classes: Configuration

Constant Summary

Constants inherited from Extension

Extension::ABSTRACT

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Initializable

included, #run_initializers

Methods inherited from AppEngine

#load_generators, #start_interfaces, #start_pipeline

Methods inherited from Extension

abstract?, #extension_name, extension_name, #extension_namespace, generators, #initialize, subclasses

Constructor Details

This class inherits a constructor from Charyf::Extension

Class Attribute Details

.called_fromObject

Returns the value of attribute called_from.



17
18
19
# File 'lib/charyf/utils/application.rb', line 17

def called_from
  @called_from
end

Class Method Details

.configObject



38
39
40
# File 'lib/charyf/utils/application.rb', line 38

def config
  instance.config
end

.find_root(from) ⇒ Object



34
35
36
# File 'lib/charyf/utils/application.rb', line 34

def find_root(from)
  Charyf::Utils.find_root_with_flag 'config/chapp.rb', from
end

.inherited(base) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/charyf/utils/application.rb', line 19

def inherited(base)
  super
  Charyf.app_class = base

  base.called_from = begin
    call_stack = caller_locations.map { |l| l.absolute_path || l.path }

    File.dirname(call_stack.detect { |p| p !~ %r[charyf[\w.-]*/lib/utils] })
  end
end

.instanceObject



30
31
32
# File 'lib/charyf/utils/application.rb', line 30

def instance
  super.run_load_hooks!
end

Instance Method Details

#configObject



59
60
61
# File 'lib/charyf/utils/application.rb', line 59

def config
  @config ||= Application::Configuration.new(self.class.find_root(self.class.called_from))
end

#configure(&block) ⇒ Object



63
64
65
# File 'lib/charyf/utils/application.rb', line 63

def configure(&block)
  instance_eval(&block)
end

#dispatcherObject



90
91
92
93
94
95
96
# File 'lib/charyf/utils/application.rb', line 90

def dispatcher
  # TODO resolve dependency on engine - maybe move the base classes to utils?
  klass = Charyf::Engine::Dispatcher.list[config.dispatcher]
  raise Charyf::Utils::InvalidConfiguration.new("No dispatcher with name '#{config.dispatcher}' found") unless klass

  klass
end

#initialize!(group = :default) ⇒ Object



44
45
46
47
48
49
# File 'lib/charyf/utils/application.rb', line 44

def initialize!(group = :default)
  return self if @initialized
  @initialized = true

  run_initializers(group, self)
end

#intent_processorsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/charyf/utils/application.rb', line 76

def intent_processors
  # TODO resolve dependency on engine - maybe move the base classes to utils?
  klasses = config.enabled_intent_processors.map do |processor_name|
    klass = Charyf::Engine::Intent::Processor.list[processor_name]
    raise Charyf::Utils::InvalidConfiguration.new("No intent processor strategy with name '#{processor_name}' found") unless klass

    klass
  end

  raise Charyf::Utils::InvalidConfiguration.new('No intent processor strategies specified') if klasses.empty?

  klasses
end

#routesObject



114
115
116
# File 'lib/charyf/utils/application.rb', line 114

def routes
  @routes ||= routing.new
end

#routingObject



106
107
108
109
110
111
112
# File 'lib/charyf/utils/application.rb', line 106

def routing
  klass = Charyf::Engine::Routing.list[config.router]

  raise Charyf::Utils::InvalidConfiguration.new("No router with name '#{config.router}' found") unless klass

  klass
end

#run_load_hooks!Object



51
52
53
54
55
56
57
# File 'lib/charyf/utils/application.rb', line 51

def run_load_hooks!
  return self if @ran_load_hooks
  @ran_load_hooks = true

  # Todo LOAD Hooks should be here
  self
end

#session_processorObject

TODO sig, nullable



68
69
70
71
72
73
74
# File 'lib/charyf/utils/application.rb', line 68

def session_processor
  # TODO resolve dependency on engine - maybe move the base classes to utils?
  klass = Charyf::Engine::Session::Processor.list[config.session_processor]
  raise Charyf::Utils::InvalidConfiguration.new("No storage processor strategy with name '#{config.session_processor}' found") unless klass

  klass
end

#storage_providerObject

TODO sig, nullable



99
100
101
102
103
104
# File 'lib/charyf/utils/application.rb', line 99

def storage_provider
  klass = Charyf::Utils::StorageProvider.list[config.storage_provider]
  raise Charyf::Utils::InvalidConfiguration.new("No storage provider with name '#{config.storage_provider}' found") unless klass

  klass
end