Module: Dependencies
- Defined in:
- lib/dependencies.rb,
lib/dependencies/factory.rb,
lib/dependencies/repository.rb
Defined Under Namespace
Classes: Factory, Repository
Class Method Summary
collapse
Class Method Details
.[](*dependencies) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/dependencies.rb', line 11
def [](*dependencies)
class_dependencies = Factory.parse([*dependencies])
Repository.push(class_dependencies:)
included_hook
end
|
.define_readers(dependencies, klass) ⇒ Object
47
48
49
50
51
|
# File 'lib/dependencies.rb', line 47
def define_readers(dependencies, klass)
klass.class_eval do
attr_reader(*dependencies.map { |d| Dependencies.name_from_namespace(d.var_name).to_sym })
end
end
|
.included_hook ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/dependencies.rb', line 20
def included_hook
Module.new do
def self.included(klass)
klass.class_eval do
@dependencies = Repository.pop
class << self
attr_reader :dependencies
end
def initialize
self.class.dependencies.each do |dependency|
provider = Providers[dependency.provider_key]
raise StandardError, "Provider #{dependency.provider_key} is missing or returning nil" if provider.nil?
var_name = Dependencies.name_from_namespace(dependency.var_name)
instance_variable_set("@#{var_name}", provider)
end
end
Dependencies.define_readers(@dependencies, self)
end
end
end
end
|
.name_from_namespace(namespace) ⇒ Object
53
54
55
56
57
|
# File 'lib/dependencies.rb', line 53
def name_from_namespace(namespace)
return namespace.split('.').last if namespace.is_a?(String)
namespace
end
|