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

#each(type = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/card/mod/dirs.rb', line 26

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



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

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



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

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

#mod(mod_name) ⇒ Object



20
21
22
23
24
# File 'lib/card/mod/dirs.rb', line 20

def mod mod_name
  @mods << mod_name
  # TODO: do something if two mods have the same name?
  @paths[mod_name] = File.join @current_path, mod_name
end