Class: RKit::Core::Loader

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

Defined Under Namespace

Classes: Dependency, LoadPath

Constant Summary collapse

@@loaded =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Loader

Returns a new instance of Loader.



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

def initialize base
  @_base = base
  @load_paths = []
  @dependencies = []
end

Instance Attribute Details

#_baseObject

Returns the value of attribute _base.



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

def _base
  @_base
end

#dependenciesObject

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

#load_pathsObject

Returns the value of attribute load_paths.



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

def load_paths
  @load_paths
end

Class Method Details

.loadedObject



6
7
8
# File 'lib/r_kit/core/loader.rb', line 6

def self.loaded
  @@loaded.map{ |name| name.demodulize.underscore }
end

.loaded?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

def self.loaded? name
  @@loaded.include? name
end

Instance Method Details

#dependencies!Object



26
27
28
# File 'lib/r_kit/core/loader.rb', line 26

def dependencies!
  dependencies.each &:load!
end

#dependency(dependency) ⇒ Object



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

def dependency dependency
  dependencies << Dependency.new(_base, service: dependency)
end

#load!Object



48
49
50
51
52
# File 'lib/r_kit/core/loader.rb', line 48

def load!
  dependencies!
  load_paths!
  loaded!
end

#load_path(file, path, options = {}) ⇒ Object



31
32
33
34
35
36
# File 'lib/r_kit/core/loader.rb', line 31

def load_path file, path, options = {}
  load_path = LoadPath.new _base, file: file, path: path
  load_path.conditions = options.slice :if, :unless

  load_paths << load_path
end

#load_paths!Object



38
39
40
# File 'lib/r_kit/core/loader.rb', line 38

def load_paths!
  load_paths.each &:load!
end

#loaded!Object



43
44
45
# File 'lib/r_kit/core/loader.rb', line 43

def loaded!
  @@loaded << _base.name
end