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



46
47
48
49
50
51
52
# File 'card/lib/cardio/mod/class_methods.rb', line 46

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 'card/lib/cardio/mod/class_methods.rb', line 16

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

#each_path(&block) ⇒ Object



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

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

#ensure_installedObject



39
40
41
42
43
44
# File 'card/lib/cardio/mod/class_methods.rb', line 39

def ensure_installed
  Card::Machine.reset_script
  Card::Cache.reset_all
  puts "installing card mods".green
  Cardio.mods.each(&:ensure)
end

#ensure_uninstalledObject



30
31
32
33
34
35
36
37
# File 'card/lib/cardio/mod/class_methods.rb', line 30

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

#gem_specsHash

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

Returns:

  • (Hash)

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



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

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



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

def missing
  Card.search(type: :mod).reject do |mod_card|
    dirs.fetch_mod mod_card.modname
  end
end

#normalize_name(name) ⇒ Object



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

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