Class: Dependency

Inherits:
Object show all
Defined in:
lib/r_kit/core/loader/dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, service:) ⇒ Dependency

Returns a new instance of Dependency.



4
5
6
7
# File 'lib/r_kit/core/loader/dependency.rb', line 4

def initialize base, service:;
  @base = base
  @service = RKit.const_get(service.to_s.classify)
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



2
3
4
# File 'lib/r_kit/core/loader/dependency.rb', line 2

def base
  @base
end

#serviceObject

Returns the value of attribute service.



2
3
4
# File 'lib/r_kit/core/loader/dependency.rb', line 2

def service
  @service
end

Instance Method Details

#dependency!Object

TODO: The dependency warning msg should be in service object



14
15
16
17
18
19
20
21
# File 'lib/r_kit/core/loader/dependency.rb', line 14

def dependency!
  warn %Q{
WARNING - #{ service.name } will be implicitly loaded,
As a dependency for #{ base }.
You may want to load it explicitly.
  }
  service.load
end

#load!Object



23
24
25
# File 'lib/r_kit/core/loader/dependency.rb', line 23

def load!
  dependency! if should_load?
end

#should_load?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/r_kit/core/loader/dependency.rb', line 9

def should_load?
  !service.loaded?
end