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
- #dependencies(name, nickname = true) ⇒ Object
-
#dirs ⇒ Object
An array of Rails::Path objects.
- #ensure_installed ⇒ Object
- #ensure_uninstalled ⇒ Object
- #fetch(mod_name) ⇒ Object
-
#gem_specs ⇒ Hash
In the form{ modname(String) => Gem::Specification }.
- #leftover ⇒ Object
- #load ⇒ Object
- #normalize_name(name) ⇒ Object
Instance Method Details
#dependencies(name, nickname = true) ⇒ Object
53 54 55 56 57 58 59 |
# File '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 |
#dirs ⇒ Object
Returns an array of Rails::Path objects.
18 19 20 |
# File 'lib/cardio/mod/class_methods.rb', line 18 def dirs @dirs ||= Mod::Dirs.new Cardio.paths["mod"].existent end |
#ensure_installed ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File '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_uninstalled ⇒ Object
34 35 36 37 38 39 40 |
# File '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 'lib/cardio/mod/class_methods.rb', line 22 def fetch mod_name dirs.fetch_mod mod_name end |
#gem_specs ⇒ Hash
Returns 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 |
#leftover ⇒ Object
30 31 32 |
# File 'lib/cardio/mod/class_methods.rb', line 30 def leftover Card.search(type: :mod).reject { |mod_card| fetch mod_card.modname } end |
#load ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File '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 'lib/cardio/mod/class_methods.rb', line 26 def normalize_name name name.to_s.sub(/^card-mod-/, "") end |