Class: Card::Mod::Loader
- Inherits:
-
Object
- Object
- Card::Mod::Loader
- Defined in:
- lib/card/mod/loader.rb,
lib/card/mod/loader/set_loader.rb,
lib/card/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
Class Attribute Summary collapse
-
.module_type ⇒ Object
readonly
Returns the value of attribute module_type.
Class Method Summary collapse
- .load_chunks ⇒ Object
-
.load_dir(dir) ⇒ Object
load all files in directory.
- .load_formats ⇒ Object
-
.load_initializers ⇒ Object
private.
- .load_mods ⇒ Object
- .module_class_template ⇒ Object
Instance Method Summary collapse
-
#initialize(load_strategy = nil, mod_dirs = nil) ⇒ Loader
constructor
A new instance of Loader.
- #load ⇒ Object
- #load_strategy_class(load_strategy) ⇒ Object
Constructor Details
#initialize(load_strategy = nil, mod_dirs = nil) ⇒ Loader
Returns a new instance of Loader.
20 21 22 23 24 25 |
# File 'lib/card/mod/loader.rb', line 20 def initialize load_strategy=nil, mod_dirs=nil load_strategy ||= Cardio.config.load_strategy mod_dirs ||= Mod.dirs klass = load_strategy_class load_strategy @load_strategy = klass.new mod_dirs, self end |
Class Attribute Details
.module_type ⇒ Object (readonly)
Returns the value of attribute module_type.
40 41 42 |
# File 'lib/card/mod/loader.rb', line 40 def module_type @module_type end |
Class Method Details
.load_chunks ⇒ Object
51 52 53 54 55 |
# File 'lib/card/mod/loader.rb', line 51 def load_chunks Mod.dirs.each(:chunk) do |dir| load_dir dir end end |
.load_dir(dir) ⇒ Object
load all files in directory
79 80 81 82 83 84 85 |
# File 'lib/card/mod/loader.rb', line 79 def load_dir dir Dir["#{dir}/*.rb"].sort.each do |file| # puts Benchmark.measure("from #load_dir: rd: #{file}") { require_dependency file # }.format('%n: %t %r') end end |
.load_formats ⇒ Object
70 71 72 73 74 75 |
# File 'lib/card/mod/loader.rb', line 70 def load_formats # cheating on load issues now by putting all inherited-from formats in core mod. Mod.dirs.each(:format) do |dir| load_dir dir end end |
.load_initializers ⇒ Object
private
63 64 65 66 67 |
# File 'lib/card/mod/loader.rb', line 63 def load_initializers Card.config.paths["mod/config/initializers"].existent.sort.each do |initializer| load initializer end end |
.load_mods ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/card/mod/loader.rb', line 42 def load_mods SetPatternLoader.new.load load_formats SetLoader.new.load load_initializers # rescue # raise Card::Error, "unrescued error loading mods" end |
.module_class_template ⇒ Object
57 58 59 |
# File 'lib/card/mod/loader.rb', line 57 def module_class_template const_get :Template end |
Instance Method Details
#load ⇒ Object
35 36 37 |
# File 'lib/card/mod/loader.rb', line 35 def load @load_strategy.load_modules end |
#load_strategy_class(load_strategy) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/card/mod/loader.rb', line 27 def load_strategy_class load_strategy case load_strategy when :tmp_files then LoadStrategy::TmpFiles when :binding_magic then LoadStrategy::BindingMagic else LoadStrategy::Eval end end |