Class: Nauvisian::ModList
- Inherits:
-
Object
- Object
- Nauvisian::ModList
- Includes:
- Enumerable
- Defined in:
- lib/nauvisian/mod_list.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(mod, enabled: nil) ⇒ Object
- #disable(mod) ⇒ Object
- #each ⇒ Object
- #enable(mod) ⇒ Object
- #enabled?(mod) ⇒ Boolean
- #exist?(mod) ⇒ Boolean
-
#initialize(mods = {}) ⇒ ModList
constructor
A new instance of ModList.
- #remove(mod) ⇒ Object
- #save(to = DEFAULT_MOD_LIST_PATH) ⇒ Object
Constructor Details
Class Method Details
.load(from = DEFAULT_MOD_LIST_PATH) ⇒ Object
12 13 14 15 |
# File 'lib/nauvisian/mod_list.rb', line 12 def self.load(from=DEFAULT_MOD_LIST_PATH) raw_data = JSON.parse(File.read(from), symbolize_names: true) new(raw_data[:mods].to_h {|e| [Mod[name: e[:name]], e[:enabled]] }) end |
Instance Method Details
#add(mod, enabled: nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/nauvisian/mod_list.rb', line 38 def add(mod, enabled: nil) raise ArgumentError, "Can't disable the base mod" if mod.base? && enabled == false @mods[mod] = enabled.nil? ? true : enabled end |
#disable(mod) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/nauvisian/mod_list.rb', line 64 def disable(mod) raise ArgumentError, "Can't disalbe the base mod" if mod.base? raise Nauvisian::ModNotFound, mod unless exist?(mod) @mods[mod] = false end |
#each ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/nauvisian/mod_list.rb', line 30 def each return @mods.to_enum unless block_given? @mods.each do |mod, enabled| yield(mod, enabled) end end |
#enable(mod) ⇒ Object
58 59 60 61 62 |
# File 'lib/nauvisian/mod_list.rb', line 58 def enable(mod) raise Nauvisian::ModNotFound, mod unless exist?(mod) @mods[mod] = true end |
#enabled?(mod) ⇒ Boolean
52 53 54 55 56 |
# File 'lib/nauvisian/mod_list.rb', line 52 def enabled?(mod) raise Nauvisian::ModNotFound, mod unless exist?(mod) @mods[mod] end |
#exist?(mod) ⇒ Boolean
50 |
# File 'lib/nauvisian/mod_list.rb', line 50 def exist?(mod) = @mods.key?(mod) |
#remove(mod) ⇒ Object
44 45 46 47 48 |
# File 'lib/nauvisian/mod_list.rb', line 44 def remove(mod) raise ArgumentError, "Can't remove the base mod" if mod.base? @mods.delete(mod) end |
#save(to = DEFAULT_MOD_LIST_PATH) ⇒ Object
26 27 28 |
# File 'lib/nauvisian/mod_list.rb', line 26 def save(to=DEFAULT_MOD_LIST_PATH) File.write(to, JSON.pretty_generate({mods: @mods.map {|mod, enabled| {name: mod.name, enabled:} }})) end |