Class: Cardio::Mod::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/cardio/mod/loader.rb,
lib/cardio/mod/loader/set_loader.rb,
lib/cardio/mod/loader/set_template.rb,
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

SetLoader, SetPatternLoader

Defined Under Namespace

Classes: SetLoader, SetPatternLoader, SetPatternTemplate, SetTemplate

Instance 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.



51
52
53
54
55
# File '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_dirsObject (readonly)

Returns the value of attribute mod_dirs.



49
50
51
# File '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

Parameters:

  • dir (String)

    directory name



38
39
40
41
42
43
44
45
46
# File '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_initializersObject



30
31
32
33
34
# File '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_modsObject



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

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

.reload_setsObject



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

def reload_sets
  Card::Set::Pattern.reset
  Card::Set.reset
  SetPatternLoader.new.load
  SetLoader.new(no_all: true).load
end

Instance Method Details

#loadObject



57
58
59
# File '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 '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