Class: Card::Mod::Dirs

Inherits:
Array
  • Object
show all
Defined in:
lib/card/mod/dirs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod_paths) ⇒ Dirs

Returns a new instance of Dirs.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/card/mod/dirs.rb', line 6

def initialize mod_paths
  @mods = []
  @paths = {}
  mod_paths = Array(mod_paths)
  mod_paths.each do |mp|
    @current_path = mp
    load_from_modfile || load_from_dir
  end
  super()
  @mods.each do |mod_name|
    self << @paths[mod_name]
  end
end

Instance Attribute Details

#modsObject (readonly)

Returns the value of attribute mods.



4
5
6
# File 'lib/card/mod/dirs.rb', line 4

def mods
  @mods
end

Instance Method Details

#add_path(mod_name) ⇒ Object Also known as: mod

add a new mod to mod load paths



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

def add_path mod_name
  if @mods.include? mod_name
    raise Error,
          "name conflict: mod with name \"#{mod_name}\" already loaded"
  end
  @mods << mod_name
  @paths[mod_name] = File.join @current_path, mod_name
end

#each(type = nil) ⇒ Object



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

def each type=nil
  super() do |path|
    dirname = type ? File.join(path, type.to_s) : path
    next unless Dir.exist? dirname
    yield dirname
  end
end

#each_tmp(type) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/card/mod/dirs.rb', line 44

def each_tmp type
  @mods.each do |mod|
    path = tmp_dir mod, type
    next unless Dir.exist? path
    yield path
  end
end

#each_with_tmp(type = nil) ⇒ Object



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

def each_with_tmp type=nil
  @mods.each do |mod|
    dirname = type ? File.join(@paths[mod], type.to_s) : @paths[mod]
    next unless Dir.exist? dirname
    yield dirname, tmp_dir(mod, type)
  end
end

#path(mod_name) ⇒ Object



32
33
34
# File 'lib/card/mod/dirs.rb', line 32

def path mod_name
  @paths[mod_name]
end