Module: Cardio::Mod::ClassMethods

Included in:
Cardio::Mod
Defined in:
card/lib/cardio/mod/class_methods.rb

Overview

class methods for Cardio::Mod

Instance Method Summary collapse

Instance Method Details

#dependencies(name, nickname = true) ⇒ Object



53
54
55
56
57
58
59
# File 'card/lib/cardio/mod/class_methods.rb', line 53

def dependencies name, nickname=true
  return unless (spec = gem_spec name, nickname)

  deps = spec&.dependencies || []
  dep_names = deps.map { |dep| dependencies dep.name, false }
  (dep_names << spec).flatten.compact.uniq
end

#dirsObject

Returns an array of Rails::Path objects.

Returns:

  • an array of Rails::Path objects



18
19
20
# File 'card/lib/cardio/mod/class_methods.rb', line 18

def dirs
  @dirs ||= Mod::Dirs.new Cardio.paths["mod"].existent
end

#ensure_installedObject



42
43
44
45
46
47
48
49
50
51
# File 'card/lib/cardio/mod/class_methods.rb', line 42

def ensure_installed
  Card::Auth.as_bot do
    Card::Cache.reset_all
    puts "installing card mods".green
    ensure_asset_lists do |hash|
      puts "ensuring mod and asset cards"
      Cardio.mods.each { |mod| ensure_asset_cards mod.ensure_card, hash }
    end
  end
end

#ensure_uninstalledObject



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

def ensure_uninstalled
  leftover.each do |mod_card|
    Card::Auth.as_bot do
      delete_auto_installed_cards mod_card
    end
  end
end

#fetch(mod_name) ⇒ Object



22
23
24
# File 'card/lib/cardio/mod/class_methods.rb', line 22

def fetch mod_name
  dirs.fetch_mod mod_name
end

#gem_specsHash

Returns in the form{ modname(String) => Gem::Specification }.

Returns:

  • (Hash)

    in the form{ modname(String) => Gem::Specification }



62
63
64
65
66
# File 'card/lib/cardio/mod/class_methods.rb', line 62

def gem_specs
  Bundler.definition.specs.each_with_object({}) do |gem_spec, h|
    h[gem_spec.name] = gem_spec if gem_spec? gem_spec
  end
end

#leftoverObject



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

def leftover
  Card.search(type: :mod).reject { |mod_card| fetch mod_card.modname }
end

#loadObject



7
8
9
10
11
12
13
14
15
# File 'card/lib/cardio/mod/class_methods.rb', line 7

def load
  return if ENV["CARD_MODS"] == "none"

  if Card.take
    Loader.load_mods
  else
    Rails.logger.warn "empty database"
  end
end

#normalize_name(name) ⇒ Object



26
27
28
# File 'card/lib/cardio/mod/class_methods.rb', line 26

def normalize_name name
  name.to_s.sub(/^card-mod-/, "")
end