Class: Cardio::Mod::Loader
- Defined in:
- card/lib/cardio/mod/loader.rb,
card/lib/cardio/mod/loader/set_loader.rb,
card/lib/cardio/mod/loader/set_template.rb,
card/lib/cardio/mod/loader/set_pattern_loader.rb
Overview
The mods are given by a Mod::Dirs object. SetLoader can use three different strategies to load the set modules.
Direct Known Subclasses
Defined Under Namespace
Classes: SetLoader, SetPatternLoader, SetPatternTemplate, SetTemplate
Instance Attribute Summary collapse
-
#mod_dirs ⇒ Object
readonly
Returns the value of attribute mod_dirs.
Class Method Summary collapse
-
.load_dir(dir) ⇒ Object
load all files in directory.
-
.load_initializers ⇒ Object
-
.load_mods ⇒ Object
-
.reload_sets ⇒ Object
Instance Method Summary collapse
-
#initialize(load_strategy: nil, mod_dirs: nil) ⇒ Loader
constructor
A new instance of Loader.
-
#load ⇒ Object
-
#parts_from_path(path) ⇒ Object
Constructor Details
#initialize(load_strategy: nil, mod_dirs: nil) ⇒ Loader
Returns a new instance of Loader.
51 52 53 54 55 |
# File 'card/lib/cardio/mod/loader.rb', line 51 def initialize load_strategy: nil, mod_dirs: nil load_strategy ||= Cardio.config.load_strategy @mod_dirs = mod_dirs || Mod.dirs @load_strategy = load_strategy_class(load_strategy).new self end |
Instance Attribute Details
#mod_dirs ⇒ Object (readonly)
Returns the value of attribute mod_dirs.
49 50 51 |
# File 'card/lib/cardio/mod/loader.rb', line 49 def mod_dirs @mod_dirs end |
Class Method Details
.load_dir(dir) ⇒ Object
load all files in directory
38 39 40 41 42 43 44 45 46 |
# File 'card/lib/cardio/mod/loader.rb', line 38 def load_dir dir Dir["#{dir}/*.rb"].sort.each do |file| # puts Benchmark.measure("from #load_dir: rd: #{file}") { # require file # "require" breaks the reloading in development env load file # }.format('%n: %t %r') end end |
.load_initializers ⇒ Object
30 31 32 33 34 |
# File 'card/lib/cardio/mod/loader.rb', line 30 def load_initializers Cardio.config.paths["late/initializers"].existent.sort.each do |init| load init end end |
.load_mods ⇒ Object
16 17 18 19 20 21 |
# File 'card/lib/cardio/mod/loader.rb', line 16 def load_mods SetPatternLoader.new.load SetLoader.new.load Card::Set.process_base_modules load_initializers end |
Instance Method Details
#load ⇒ Object
57 58 59 |
# File 'card/lib/cardio/mod/loader.rb', line 57 def load @load_strategy.load_modules end |
#parts_from_path(path) ⇒ Object
61 62 63 64 65 |
# File 'card/lib/cardio/mod/loader.rb', line 61 def parts_from_path path # remove file extension and number prefixes parts = path.gsub(/\.rb/, "").gsub(%r{(?<=\A|/)\d+_}, "").split(File::SEPARATOR) parts.map(&:camelize) end |