Module: Cardio::Mod::ClassMethods

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

Overview

class methods for Cardio::Mod

Instance Method Summary collapse

Instance Method Details

#dependencies(name, nickname = true) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/cardio/mod/class_methods.rb', line 48

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



16
17
18
# File 'lib/cardio/mod/class_methods.rb', line 16

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

#each_path(&block) ⇒ Object



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

def each_path &block
  each_simple_path(&block)
  each_gem_path(&block)
end

#ensure_installedObject



41
42
43
44
45
46
# File 'lib/cardio/mod/class_methods.rb', line 41

def ensure_installed
  Card::Cache.reset_all
  puts "installing card mods".green
  Cardio.mods.each(&:ensure)
  Card::Assets.refresh_assets force: true
end

#ensure_uninstalledObject



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

def ensure_uninstalled
  missing.each do |mod_card|
    Card::Auth.as_bot do
      Card[:all, :style].drop_item mod_card
      delete_auto_installed_cards mod_card
    end
  end
end

#fetch(mod_name) ⇒ Object



20
21
22
# File 'lib/cardio/mod/class_methods.rb', line 20

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 '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

#loadObject



5
6
7
8
9
10
11
12
13
# File 'lib/cardio/mod/class_methods.rb', line 5

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

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

#missingObject



28
29
30
# File 'lib/cardio/mod/class_methods.rb', line 28

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

#normalize_name(name) ⇒ Object



24
25
26
# File 'lib/cardio/mod/class_methods.rb', line 24

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