Class: Card::Mod::Loader

Inherits:
Object
  • Object
show all
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

SetLoader, SetPatternLoader

Defined Under Namespace

Classes: SetLoader, SetPatternLoader

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_strategy: nil, mod_dirs: nil) ⇒ Loader

Returns a new instance of Loader.



15
16
17
18
19
20
# File 'lib/card/mod/loader.rb', line 15

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_typeObject (readonly)

Returns the value of attribute module_type.



35
36
37
# File 'lib/card/mod/loader.rb', line 35

def module_type
  @module_type
end

Class Method Details

.load_chunksObject



54
55
56
57
58
# File 'lib/card/mod/loader.rb', line 54

def load_chunks
  Mod.dirs.each(:chunk) do |dir|
    load_dir dir
  end
end

.load_dir(dir) ⇒ Object

load all files in directory

Parameters:

  • dir (String)

    directory name



82
83
84
85
86
87
88
89
90
# File 'lib/card/mod/loader.rb', line 82

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_formatsObject



73
74
75
76
77
78
# File 'lib/card/mod/loader.rb', line 73

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_initializersObject

private



66
67
68
69
70
# File 'lib/card/mod/loader.rb', line 66

def load_initializers
  Card.config.paths["mod/config/initializers"].existent.sort.each do |initializer|
    load initializer
  end
end

.load_modsObject



37
38
39
40
41
42
43
# File 'lib/card/mod/loader.rb', line 37

def load_mods
  load_formats
  Card::Mod::Loader::SetPatternLoader.new.load
  Card::Mod::Loader::SetLoader.new.load
  Card::Set.process_base_modules
  load_initializers
end

.module_class_templateObject



60
61
62
# File 'lib/card/mod/loader.rb', line 60

def module_class_template
  const_get :Template
end

.reload_setsObject



45
46
47
48
49
50
51
52
# File 'lib/card/mod/loader.rb', line 45

def reload_sets
  Card::Set::Pattern.reset
  Card::Set.reset_modules
  Card::Mod::Loader::SetPatternLoader.new.load
  Card::Mod::Loader::SetLoader.new(
    patterns: Card::Set::Pattern.nonbase_loadable_codes
  ).load
end

Instance Method Details

#loadObject



30
31
32
# File 'lib/card/mod/loader.rb', line 30

def load
  @load_strategy.load_modules
end

#load_strategy_class(load_strategy) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/card/mod/loader.rb', line 22

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