Class: RKit::Core::Loader
Instance Attribute Summary collapse
-
#_base ⇒ Object
Returns the value of attribute _base.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#load_paths ⇒ Object
Returns the value of attribute load_paths.
Class Method Summary collapse
Instance Method Summary collapse
- #dependencies! ⇒ Object
-
#dependency(*services) ⇒ Object
TODO: when a dependency is added, we must define in the opposite service a “dependency forbidden” TODO: in order to avoid recursive dependency.
-
#initialize(base) ⇒ Loader
constructor
A new instance of Loader.
- #load! ⇒ Object
- #load_path(file, *paths, **options) ⇒ Object
- #load_paths! ⇒ Object
- #loaded! ⇒ Object
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
#_base ⇒ Object
Returns the value of attribute _base.
2 3 4 |
# File 'lib/r_kit/core/loader.rb', line 2 def _base @_base end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
2 3 4 |
# File 'lib/r_kit/core/loader.rb', line 2 def dependencies @dependencies end |
#load_paths ⇒ Object
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
.loaded ⇒ Object
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
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
30 31 32 |
# File 'lib/r_kit/core/loader.rb', line 30 def dependencies! dependencies.each &:load! end |
#dependency(*services) ⇒ Object
TODO: when a dependency is added, we must define in the opposite service a “dependency forbidden” TODO: in order to avoid recursive dependency
24 25 26 27 28 |
# File 'lib/r_kit/core/loader.rb', line 24 def dependency *services services.each do |service| dependencies << Dependency.new(_base, service: service) end end |
#load! ⇒ Object
51 52 53 54 55 |
# File 'lib/r_kit/core/loader.rb', line 51 def load! dependencies! load_paths! loaded! end |
#load_path(file, *paths, **options) ⇒ Object
35 36 37 38 39 |
# File 'lib/r_kit/core/loader.rb', line 35 def load_path file, *paths, ** paths.each do |path| load_paths << LoadPath.new(_base, file: file, path: path, **.slice(:priority, :if, :unless)) end end |
#load_paths! ⇒ Object
41 42 43 |
# File 'lib/r_kit/core/loader.rb', line 41 def load_paths! load_paths.sort{ |a, b| a.priority <=> b.priority }.each &:load! end |
#loaded! ⇒ Object
46 47 48 |
# File 'lib/r_kit/core/loader.rb', line 46 def loaded! self.class.instance_variable_get("@loaded") << _base.name end |