class Cardio::Mod

A Card Mod (short for “module” or “modification”) is a library containing discrete chunk of card functionality. Mods are how the Decko community develops and shares code. If you want to customize a deck in a way that can’t be done on the site itself, try a mod.

The simplest way to add a mod is to run this command in your deck:

card generate mod MOD_NAME

# or, for short:
card g mod MOD_NAME

This will create a directory following the pattern ‘DECK_NAME/mod/MOD_NAME`. This directory contains all the specifications of your mod. By default that includes a README.md file and the subdirectories in bold below:

Mods also often contain a .gemspec file to specify the mod as a ruby gem.

Learn more:

- {Card} introduces card objects
- {Card::Set} explains of how set modules work

Attributes

group[R]
index[R]
name[R]
path[R]
spec[R]

Public Class Methods

new(name, path, group:, index:, spec: nil) click to toggle source
# File lib/cardio/mod.rb, line 47
def initialize name, path, group:, index:, spec: nil
  @name = Mod.normalize_name name
  @path = required_path path
  @group = group || :custom
  @index = index
  @spec = spec
end

Public Instance Methods

codename() click to toggle source
# File lib/cardio/mod.rb, line 59
def codename
  "mod_#{name}"
end
ensure_card() click to toggle source
# File lib/cardio/mod.rb, line 76
def ensure_card
  if Card::Codename.exist? codename
    card = Card.fetch codename.to_sym
    card.update type: :mod unless card.type_code == :mod
    card
  else
    Card.create name: mod_card_name, type: :mod, codename: codename
  end
end
mod_card_name() click to toggle source
# File lib/cardio/mod.rb, line 55
def mod_card_name
  "mod: #{name.tr '_', ' '}"
end
subpath(*parts, force: false) click to toggle source
# File lib/cardio/mod.rb, line 63
def subpath *parts, force: false
  path = File.join [@path] + parts
  return path if File.exist? path
  return unless force

  FileUtils.mkdir_p path
end
tmp_dir(type) click to toggle source
# File lib/cardio/mod.rb, line 71
def tmp_dir type
  File.join Cardio.paths["tmp/#{type}"].first, @group.to_s,
            "mod#{'%03d' % (@index + 1)}-#{@name}"
end

Private Instance Methods

required_path(path) click to toggle source
# File lib/cardio/mod.rb, line 88
def required_path path
  return path if File.exist? path

  raise StandardError, "mod not found: #{@name}"

  # FIXME: - need non-Card based error class
  # raise Card::Error::NotFound,
end